Open JoppeDC opened 4 years ago
Maybe using another event related to the product show page would be a better idea and then adding a block extending the metatags block into the twig file linked to this event.
Here is the template : https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ShopBundle/Resources/views/Product/show.html.twig
Then choose a generic event (eg: one who will not be removed by a custom logic), maybe the sylius.shop.product.show.after_product_header
event is the best choice.
Into the twig file affected to this event add this kind of code :
{% block metatags %}
{{ parent() }}
{# add those custom meta tags #}
{% endblock %}
@Prometee That is an excellent idea. There is already a metatags block in the default layout template, if we can extend this block it can be rendered in the head directly without the Javascript functions! I'm going to give it a try 😏
@Prometee Only issue i'm guessing is that you cant just extend blocks in a sonata block event. I've done a quick test on a clean project and it wont let me render blocks in an event template. If i include the layout.html.twig
it'll just render the page inside itself
@prometee Feel free to give it a try! If it works, just open a PR and i’ll check it out 😉
@JoppeDC So I think the only way is to make a twig extension, it will allow use to make everything we want... I'm trying to understand how it could be done right I will made a PR if I found a way.
I've been looking at the Setono's Tag Bag Plugin / Sylius Analytics Plugin, they put their library tags in the head thru event suscribers probably some good inspiration there.
@tuala thanks for the heads up! I’ll definetly give it a look 😉
Currently we're using javascript to create meta tags in the header, from the body. The cleanest way would be if we could render the
_seo_block
directly in the header itself.This can be done using the sonata block render event
sylius.shop.layout.head
. The problem is that we can't access the product in this context._seo_block
render to head