Log in Sign up

Hide or show certain sections depending on metadata?

I'm wondering if there's a simple way to hide a section from a page template if a certain metadata is specified. A bit like with Menu: No which hides a page from the navbar. I'd like to create a Hero Image: No which would disable the top image on a blog post. Your help is much appreciated :)


a year ago, 4 replies   developers   metadata   Edit question

For sure, let's say you use the following metadata in your post:

Hero: yes

You can then do this in your template to only show a hero image when 'hero' metadata is set:

{{#entry}}
{{#metadata.hero}}
<img src="...">
{{/metadata.hero}}
{{/entry}}

You could even specify an image URL/path in your hero metadata, and then use that in your template:

Hero: /path/to/image.png
{{#entry}}
{{#metadata.hero}}
<img src="{{metadata.hero}}">
{{/metadata.hero}}
{{/entry}}
Answered a year ago · Edit answer

I believe that the person was asking about hiding a section from a page, not how to display one from meta

Answered a year ago · Edit answer

Yes exactly! But David's solution works just fine. Instead of specifying when I dont want something to show, I specify when I do :) If empty, the thing doesn't show.

Answered a year ago · Edit answer

Great, glad it's sorted – please let me know if you have any questions about this or anything else

Answered a year ago · Edit answer