I’ve been using named tags on the product model to add metadata to product page & in search results. This has been great so far, particularly for lists (arrays) of metadata that need to be associated with a particular product.
However, one issue I’ve run into is that Hogan doesn’t seem to render lists of 1.
I’ve been using this code to render named tags in the
<div class="col-xs-2 c-ais-species_reactivity"> [[# named_tags.speciesReactivity ]] <span class="reactivity_item" data-application="[[ . ]]"></span> [[/ named_tags.speciesReactivity ] </div>
(Ignore the fact that
[[ . ]] is in the data-attribute field that’s just one little hack I had to do to get the list to display the right way on the product page and in the search results.)
This code is working great for products that have more than 1
speciesReactivity named tag, however, if it only has 1 named tag, it doesn’t pull the value. You can see this in the column “Species Reactivity” on this page (password: xenopus).
The same issue is happening in the “Application” column on that page as well.
Also, I tested changing my code to this:
<div class="col-xs-2 c-ais-species_reactivity"> [[# named_tags.speciesReactivity ]] <span class="reactivity_item" data-application="[[ named_tags.speciesReactivity ]]"></span> [[/ named_tags.speciesReactivity ] </div>
Which resulted in the opposite error, products with exactly 1 speciesReactivity named_tag displayed, but those with more than 1 did not.
Any insights? I have thought about putting both
[[ . ]] and
[[ speciesReactivity ]] inside the block, but it duplicates. Is there a way to check if the list has 1 item? Or use some if/else statements?
Appreciate the insight!