Can I access declared vars via keywords


(Evan Wills) #1

I'm building a new site design. In our new design I've got a right column with a number of images all of which I want to be able to customise. I'd like to simplify adding the images to the design so you can just set the image ID in a declared var and a bit of nested content will take care of the formatting e.g.

    %declared_var_image_id^as_asset:asset_attribute_alt%

I’ve used “declared_var” as a keyword because I don’t know if there’s one I can use.



I’ve looked in the design documentation for declared vars and the documentation for declared vars but couldn’t find anything about this. One of my colleagues suggested using declared vars but this relates to PHP $_SERVER variables and won’t give me what I need.


(Anthony Barnes) #2

How about adding that id as a metadata value on the site asset? That would take care of your 'global' setting without having to create a design customisation each time you want to change it.

    
    %globals_site_metadata_image_id^as_asset:asset_attribute_alt%

(Evan Wills) #3

Hi Anthony


I'm already using the metadata as an override in the design vars. Problem is that metadata doesn't cascade as cleanly and can't be as easily replaced. Also in some of our top level pages, the hippo for cascading the metadata value would take too long. If I could access design declared vars it would be much cleaner, especially if I can use keyword modifiers. (The code I'm using is almost identical to your suggestion.)


(Anthony Barnes) #4

[quote]
Problem is that metadata doesn't cascade as cleanly and can't be as easily replaced

[/quote]



No worries. I'm not suggesting that you cascade it across the entire site though, just to one asset (the site asset). I'm not really sure how you want the image to be customised though. Perhaps investigate the use of paint layouts and conditional keywords as a method for producing different output based on any number of rules.


(Evan Wills) #5

Updated example:

NOTE: I have a very complicated and large parse file. I’d like to move some of the show_if blocks out of the parse file and into nested assets or paint layouts.

This is how I’d like the functionality to work.

In my parse file, I have a declared vars block like so:

<MySource_AREA id_name="cascading_default_blocks" 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>

In my paint layout I have conditional keywords to use custom or default nested assets:

%begin_asset_metadata_block_1_id%
%asset_metadata_block_1_id^as_asset:asset_contents_raw%
%else_asset_metadata_block_1_id%
%declared_vars_cascading_default_blocks_block_1_asset_id^as_asset:asset_contents_raw%
%end_asset_metadata_block_1_id%

Using this method, I can pull out single (and nested) show_if blocks used for cascaded nested content.

NOTE: cascading metadata values is not a viable alternative because:

  • if you update a metadata value on an ancestor and cascade the new value, if that value is overridden on decendant the cascade may wipe out the decendants override.
  • Also if an asset is temporarily archived the cascade won’t apply to arcived decendants so when that asset is made live, it won’t have the current metadata value.
  • The other thing about cascading a metadata value is that for our site like ours, which can have tens of thousands of decendant assets, the HIPO required for such a cascacde WILL fail if it can even start.
    (The schema is applied to hundreds of thousands of assets.)

Matrix keyword to use value of "declared var" in content