Codixio
Codixio

Reputation: 101

Shopware6.5 App Twig Get Shopware Storefront Version?

I was not able to receive the current Storefront Version via Twig, is there no global variable available to read out?

I also tried to read the composer.json, but failed, maybe the app has not enough rights to access it.

            {% set composer_json_path = path('base_path') ~ 'composer.json' %}
            {% set composer_json = file_get_contents(composer_json_path) %}
            {% set composer_data = composer_json|json_decode() %}
            {% set shopware_sf_version = composer_data.require['shopware/storefront']|replace({'~v': ''})|float %}

            Shopware_Version: {{ shopware_sf_version }} !

Is it possible to retrieve the Storefront Version, the goal is, I'd like to change a small section in the code depending if it is >=6.4 or >=6.5. Thank you.

Upvotes: 1

Views: 189

Answers (1)

dneustadt
dneustadt

Reputation: 13161

Starting with 6.5.1.0 you can use version_compare with the new global shopware.version.

{% if version_compare('6.5.2', shopware.version, '<=') %}
    {# 6.5.2 or lower compatible code #}
{% else %}
    {# 6.5.3 or higher compatible code #}    
{% endif %}

You could then use it in scripts for data loading hooks to set an extension to the page object and use the extension in the corresponding templates.

Unfortunately I'm not aware of a possibility to do this with versions prior to 6.5.1.0.

Upvotes: 1

Related Questions