Matrix Version: 5.4.3.1
(Note: this is an continuation of Can I access declared vars via keywords)
I would like to be able to access the value of design “declared_vars” via matrix keywords within content divs and or paint layouts.
We have a VERY large (kitchen sink) parse file that uses a lot of SHOW_IF blocks to switch between default content set via customizations and asset specific content set via metadata.
e.g.
<!-- Default content set via design customisation -->
<MySource_AREA id_name="content_via_customisation" design_area="nest_content" print="no">
<MySource_SET name="type_codes" value="page" />
</MySource_AREA>
<!-- Content specified on a per asset basis via metadata -->
<MySource_AREA id_name="content_via_metadata" design_area="nest_content" print="no">
<MySource_SET name="type_codes" value="page" />
</MySource_AREA>
<!-- show_if to switch between default and metadata defined content -->
<MySource_AREA id_name="showif_block_1_id" design_area="show_if">
<MySource_SET name="condition" value="keyword_regexp" />
<MySource_SET name="condition_keyword" value="asset_metadata_block_1_id" />
<MySource_SET name="condition_keyword_match" value="^[0-9]+$" />
<MySource_THEN>
<!-- START: #content_via_metadata -->
<MySource_PRINT id_name="content_via_metadata" />
<!-- END: #content_via_metadata -->
</MySource_THEN>
<MySource_ELSE>
<!-- START: #content_via_customisation -->
<MySource_PRINT id_name="content_via_customisation" />
<!-- END: #content_via_customisation -->
</MySource_ELSE>
</MySource_AREA>
The benefit of this approach is that our parse file is very flexible. The disadvantage is that once you have a few customisations and they also get customised making changes to the parse file becomes very difficult because of time out issues when reparsing the parse file.
What I would like to do is use declared_vars to specify asset IDs for the default content then use Matrix Conditional keywords to call the asset specified in the DECLARED_VARS unless there is something specified in metadata.
e.g. in my Design parse file I would have:
<MySource_AREA id_name="cascading_default_ids" design_area="declared_vars" print="no">
<MySource_DECLARE name="block_1_asset_id" value="" type="text" description="ID of asset to be used as default content for block 1 (can be over-ridden by metadata)" />
</MySource_AREA>
<MySource_AREA id_name="declared_vars_switcher" design_area="nest_content">
<MySource_SET name="type_codes" value="page" />
</MySource_AREA>
In my metadata I’d have a “related asset” fields called block_1_id
which could be used to over-ride the declared var id.
In my paint layout or nested asset, I could use a “declared_vars” keyword inside a conditional keyword block like so:
%begin_asset_metadata_block_1_id%
<!-- block 1 - override content (per asset) -->
%asset_metadata_block_1_id^as_asset:asset_contents_raw%
%else_asset_metadata_block_1_id%
<!-- block 1 - default content (set by parse file or customisation) -->
%globals_declared_vars_cascading_default_ids_block_1_asset_id^as_asset:asset_contents_raw%
%end_asset_metadata_block_1_id%
With this method, I could remove two out of the three design area blocks need to implement each SHOW_IF block. For my parse file, that translates removing 30 out of 45 design area blocks, which greatly simplifies my parse file and makes it more maintainable.