Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out a way to render block in head #1

Open
JoppeDC opened this issue Oct 7, 2019 · 7 comments
Open

Figure out a way to render block in head #1

JoppeDC opened this issue Oct 7, 2019 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@JoppeDC
Copy link
Owner

JoppeDC commented Oct 7, 2019

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.

  • Find a way to access product in head context
  • Move _seo_block render to head
@JoppeDC JoppeDC added enhancement New feature or request hacktoberfest labels Oct 7, 2019
@Prometee
Copy link

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 %}

@JoppeDC
Copy link
Owner Author

JoppeDC commented Oct 23, 2019

@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 😏

@JoppeDC
Copy link
Owner Author

JoppeDC commented Oct 23, 2019

@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

@JoppeDC
Copy link
Owner Author

JoppeDC commented Oct 23, 2019

@Prometee Feel free to give it a try! If it works, just open a PR and i’ll check it out 😉

@Prometee
Copy link

@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.

@JoppeDC JoppeDC added help wanted Extra attention is needed and removed hacktoberfest labels Apr 28, 2020
@tuala
Copy link
Contributor

tuala commented May 22, 2020

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.

@JoppeDC
Copy link
Owner Author

JoppeDC commented May 23, 2020

@tuala thanks for the heads up! I’ll definetly give it a look 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants