Have you seen our video tutorials? Check 'em out!

Override pages/posts metadata for custom templates

hugogilmar - 1 month ago

Hi,

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.

Thanks

Answer

ryanthompson - 1 month ago

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!

ryanthompson - 1 month ago

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 - 1 month ago

It works! Thanks.