Dynamic metatag

Hello everyone;

might be simple; but I’m more comfortable with file configuration than twig and php :wink:
anyway…

in the file templates/partials/metatag.html.twig

the behaviour I expect as a result is :

if page/post contain a description show this description as a metatag
else show the meta description of the site.

I try to make something like this :

...  
      {% if meta.description %}description="{% if header.description %}{{ header.description }}{% else %}{{ meta.description }}{% endif %}" {% endif %}  
...  

I also tried something like this

which make me a little bit closer because the page/post part works but the meta.description don’t make it.

...
<meta name="description" content="{% if header.description %}{{ header.description|e('html') }}{% else %}{{ meta.description|e('html') }}{% endif %}">
...

Any finger pointing I’m a good direction will be appreciate :wink:

Have a nice day

J.

Hello Jodumont,
Try out this
Code

Regards
Teju,
Node js Developer

Please provide more contextual template code, specifically I am wondering from your examples:

  • what is the the value of meta - is there somewhere you’ve set this to page.header.metadata?

There are a couple of shorter Twig ways to output values if they exist (though I wouldn’t mess with this in the first place unless you understand it completely):