Check Login Status in Twig / Theme

Hi community,

I want to show a certain meta-information in the product-detail-page, but only if the user is logged in. This

{% if $sUserLoggedIn %}

....

{% endif %}

doesn’t work and I can’t find anything about that in the docs. Can anyone point me in the right direction oder just plainly tell me how I can check the user logged in status in the twig?

Thanks in advance!

MKFS

well i did this by looking for the customer group and comparing it to a „whitelist“ set in the plugin configuration

{% for customerGroupID in shopware.config.SynlabHideProductPrices.config.allowedCustomerGroups if not break %}
{% if (customerGroupID == context.currentCustomerGroup.id) %}
{% set showPrices = true %}
{% set break = true %}
{% endif %}
{% endfor %}

{% if showPrices %}
{% block component_product_box_price %}
{% sw_include ‚@Storefront/storefront/component/product/card/price-unit.html.twig‘ %}
{% endblock %}

{% block component_product_box_action %}
{% sw_include ‚@Storefront/storefront/component/product/card/action.html.twig‘ %}
{% endblock %}
{% endif %}

i’m actually not quite sure of you can check for a „being logged in“ 

{% if context.customer %}

Shopware Cache need to be disabled

1 „Gefällt mir“

@Moorleiche
This seems to work, even with cache enabled. Therefore I’m wondering if this is the correct way to hide elements for guests? Seems like a pretty solid solution, isn’t it?
Thanks

Hi, i’ve got a question, is it for sure that you need to disable the cache to check if the customer is logged in?
i wanna try to add a condition in my child theme to check if a customer is logged in and if not, to hide the product prices if possible, instead of buying a plugin for that.
Haven’t found anything on other pages or documentation so far.