Double quotes in keyword modifiers


(Tim Davison) #1

Not sure if this is correct place - looked for whether this had been discussed anywhere else.

 

I'm trying to use double quotes in an asset listing.  Assets listed have a related asset metadata field which points to an image asset.  In the listing the image is listed like a thumbnail (but not a thumbnail).  Having image is optional, so some assets in the listing should show an image and some should not.

 

I'm currently using this:

 

<img src="%asset_metadata_XXX.Image_asset_url%" alt="" />
 
and use CSS classes, etc to hide the image completely when it is empty.  This looks fine but it still leaves a useless, empty img tag in the source code.  My web crawler reports a broken link (treats empties as a fail), which of itself is not a major issue either, I think I'm just a perfectionist.

 

What I'd like to use is something like this:

 

%asset_metadata_XXX.Image^notempty:<img src="%
%asset_metadata_XXX.Image_asset_url%
%asset_metadata_XXX.Image^notempty:" alt="" />%
 
Line breaks are just to show the idea.  So if the metadata field is empty no HTML ever gets written.  However, whenever I put a double quote in the keywords no longer work (in fact the entire design fails).  I've tried escaping using \" but then the keyword is completely ignored.  I've even tried using &#34; (which I have used before in time formats) which renders fine in the browser for human reading but for generating raw HTML code.  Using single quotes instead of double quotes works fine but then my HTML validation fails.
 
Another way I've though to do it is nest another listing within the type format for the asset returned and use the metadata field related asset as the root replacement.  I think this would work, but it seems a lot of effort for something that should be relatively easy, and I'm not sure what performance impact that would have (probably not worth considering once the page has been placed in cache).
 
So, question is, can double-quotes be used in keyword modifiers?  If so, how?
 
I'm on Matrix v4.4.3.
 
Cheers

(Nic Hubbard) #2

If I were you, I would use a paint layout applied to the Asset Listing, then use the %asset_contents% keyword in the type format.  Then, you can use the Paint Layouts type format and the conditional keywords feature.  Set it up to check your asset_metadata_XXX.Image_asset_url metadata field using a regex check with $^. This will check to see if that field is empty.  Then, using the conditional keywords, you can show any hide markup based on if that metadata field is empty. 

 

Sorry for the quick explanation, but it will work extremely well.


(Joel Porgand) #3

A little late perhaps, but could you just use %asset_metadata_XXX.Image_image_tag% to render your images - letting matrix add the image tags instead of hardcoding them yourself? If the metadata field is empty it should just show nothing.