smiady
smiady

Reputation: 135

Shopware 6 override twig block plugin

I installed some plugin. I want to override the block named "neti_store_locator_detail_config" in the file vendor/store.shopware.com/netinextstorelocator/src/Resources/views/storefront/store_locator/detail.twig

{% sw_extends '@Storefront/storefront/base.html.twig' %}

{% block base_content %}
    {% block neti_store_locator_detail %}
        <div class="neti-next-store-locator-detail">
        {% block neti_store_locator_detail_config %}
            <input type="hidden" value="{{ page.config|json_encode|escape }}" ref="config">
            <input type="hidden" value="{{ page.store|json_encode|escape }}" ref="store">
        {% endblock %}
        ...

So I created plugin by command bin/console plugin:create SwagStoreLocator and create file custom/plugins/SwagStoreLocator/src/Resources/views/storefront/store_locator/detail.twig

{% sw_extends '@Storefront/storefront/base.html.twig' %}

{% block neti_store_locator_detail_config %}
    <div>Not working :(</div>
{% endblock %}

Then I installed and turned on plugin in the admin panel. I typed bin/console cache:clear and bin/console theme:compile. Unfortunately there is not errors, no override … How can I edit only twig from plugin. I don't want to do it in the vendor folder, because it's not allowed to commit such folders.

Upvotes: 1

Views: 1288

Answers (1)

Andy
Andy

Reputation: 26

I know how annoying it can become when overwrites silently just won't work. I think there are two issues here. When overwriting /netinextstorelocator/src/Resources/views/storefront/store_locator/detail.twig, you need to adjust the sw_extends command in the twig-template:

{% sw_extends '@Storefront/storefront/store_locator/detail.twig' %}

{% block neti_store_locator_detail_config %}
    <div>Not working :(</div>
{% endblock %}

This may already work when the folder-structure and extends are set correctly. If not, you have to set the "overwrite-hierarchy" in a config file called "theme.json". Please have a look at this documentation here: https://developer.shopware.com/docs/guides/plugins/themes/theme-configuration

{
  ...
  "views": [
     "@Storefront",
     "@NetiNextStoreLocator",
     "@SwagStoreLocator",
     "@Plugins"
  ],
  ...
}

In the example above I already inserted both of your plugins. The templates will be rendered in the defined order: Shopware > NetiStoreLocator > your plugin > all other plugins

Upvotes: 1

Related Questions