Adding meta to the document_head file based on the current page

5 Comments

  • Greg - Community Manager
    Comment actions Permalink

    Hi Italo! I tried something out here and it seemed to work for me without issue, so I'll share what I did, along with links to the relevant docs. I wasn't doing anything to the meta and I don't know of a good way to test it in real time, so if you have any advice on that front, please share that!

    Because the `if` statement is baked into Handlebars, it appears to be too clunky to evaluate anything other than top level object itself, as opposed to any of the object's properties. For that reason, I tried this out with an `is` statement instead and it gave me the results that I was going for and hopefully will help you:

    {{#is article.title 'Taking the Hobbits to Isengard'}}
    // meta goes here
    {{/is}}

    You don't have to use `article.title` either, you can use any of the article's properties listed here. Let us know if this works out for you!

    0
  • Italo Borges
    Comment actions Permalink

    Hi Greg! Thanks for your answer but I'm afraid it doesn't apply to my problem.

    In the document_head template file, I don't have access to a property to check the current page in order to show or not the meta. This code of yours works just if you are in an article template.

    To test the meta, actually, just see if it appears in your document tree. Or in your Google Console Tool.

    0
  • Jogi Baba
    Comment actions Permalink

    Yes, that's the answer I wanted to know to thank you very much.

    0
  • Greg - Community Manager
    Comment actions Permalink

    Hi Italo, thanks for clarifying that for me! Unfortunately there would not be a way to do that since we don't have any global helpers for articles and there are no specific helpers that we have for the document head template. 

    While this is not a great suggestion at all, the best advice that we've previously given is to utilize User Segments on articles that you don't want crawled, as they will be behind authentication. The obvious downside here being if you don't want the content behind authentication, it creates new problems.

    I wish I had better news here!

    0
  • Adam Uduste
    Comment actions Permalink

    Tes, in agreement 

    0

Please sign in to leave a comment.

Powered by Zendesk