Design if metadata value not empty


(Tim Trodd) #1

Hi All,

 

I have the following:

 

            <MySource_AREA id_name="microsite_name_not_specified" design_area="show_if">             <MySource_SET name="condition" value="keyword_regexp"/>
            <MySource_THEN>
            <div class="microsite-name">
              <a class="microsite-link" href="%globals_site_metadata_Header.Microsite.Link%" >
 
              <img src="%globals_site_metadata_Header.Microsite.Logo^as_asset:asset_url%" alt="%globals_site_metadata_Header.Microsite.Logo^as_asset:asset_attribute_alt%"/>
              </a>
            </div>
            </MySource_THEN>
            </MySource_AREA>
 

 

What I would like is for each line to only print if the metadata value is not empty. If it is empty I do not want it to print e.g. I want it still to print the microsite name if the name is present but if the logo isnt then not to print that line.

 

I have tried adding a print=no to the beginning but can't get it to work.

 

Cheers,

 

Tim

 

 


(Tim Davison) #2

First up, your show if is missing a condition.  You need to include settings for 'condition_keyword' and 'condition_keyword_match' so it's got something to compare.  At the moment it's not comparing anything so will always fail.  

 

Having said that it's probably easier to just do a keyword with replace_keywords modifier instead of a complete design area. E.g.

%globals_site_metadata_Header.Microsite.Logo^replace_keywords:notempty:
  <img src="{globals_site_metadata_Header.Microsite.Logo^as_asset:asset_url}" alt="{globals_site_metadata_Header.Microsite.Logo^as_asset:asset_attribute_alt}" />
^trim%

If the metadata field is empty then the image will not be rendered.


(Tim Trodd) #3

First up, your show if is missing a condition.  You need to include settings for 'condition_keyword' and 'condition_keyword_match' so it's got something to compare.  At the moment it's not comparing anything so will always fail.  

 

Having said that it's probably easier to just do a keyword with replace_keywords modifier instead of a complete design area. E.g.

%globals_site_metadata_Header.Microsite.Logo^replace_keywords:notempty:
  <img src="{globals_site_metadata_Header.Microsite.Logo^as_asset:asset_url}" alt="{globals_site_metadata_Header.Microsite.Logo^as_asset:asset_attribute_alt}" />
^trim%

If the metadata field is empty then the image will not be rendered.

Excellent, thanks Tim that works great.