Override pages/posts metadata for custom templates
Created 7 years ago by hugogilmar


I'm trying to override posts module behaviour for public templates. I need to add metadata on templates like opengraph/twitter cards info (custom fields added to page/posts streams) to Post/Page loader class.

I'm working on a extra theme for my project, what you guys recommend, should I override these classes? (I don't have any idea how to do that) or working with twig deferred block calling $template->set on templates for my extra metadata?. I don't want to use page or post helper, so I can have a standard template for those.

I hope you can understant what I'm asking about.


ryanthompson  —  7 years ago Best Answer

I would approach it this way:

Add your block of code in metadata and assume there is a template.post value:

{% if template.post.id %}
{% include "theme::partials/post-meta" %}
{% endif %}

There are a lot of ways you can do this - but this is most likely the easiest / fastest. You can add another if statement for template.page for example. Most of the core addons add contextual stuff that's being "viewed" to the template super variable.

Hope this helps!

hugogilmar  —  7 years ago

It works! Thanks.