# Check Login Status in Twig / Theme

**URL:** https://forum.shopware.com/t/check-login-status-in-twig-theme/72117
**Category:** Programming (EN)
**Created:** [15. Januar 2021 um 09:26 UTC](https://forum.shopware.com/t/check-login-status-in-twig-theme/72117 "2021-01-15T09:26:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MKFS](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@MKFS](https://forum.shopware.com/u/MKFS)
#### Post date: [15. Januar 2021 um 09:26 UTC](https://forum.shopware.com/t/check-login-status-in-twig-theme/72117/1 "2021-01-15T09:26:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![FSA](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@FSA](https://forum.shopware.com/u/FSA)
#### Post date: [22. Januar 2021 um 15:29 UTC](https://forum.shopware.com/t/check-login-status-in-twig-theme/72117/2 "2021-01-22T15:29:12Z")

</div>

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“&nbsp;

---

<div class="post-metadata">

### Author: ![Moorleiche](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@Moorleiche](https://forum.shopware.com/u/Moorleiche)
#### Post date: [22. Januar 2021 um 15:42 UTC](https://forum.shopware.com/t/check-login-status-in-twig-theme/72117/3 "2021-01-22T15:42:13Z")

</div>

{% if context.customer %}

Shopware Cache need to be disabled

---

<div class="post-metadata">

### Author: ![zlep](https://avatars.discourse-cdn.com/v4/letter/z/9de0a6/32.png) [@zlep](https://forum.shopware.com/u/zlep)
#### Post date: [5. Januar 2022 um 16:40 UTC](https://forum.shopware.com/t/check-login-status-in-twig-theme/72117/4 "2022-01-05T16:40:13Z")

</div>

@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

---

<div class="post-metadata">

### Author: ![SauerC](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@SauerC](https://forum.shopware.com/u/SauerC)
#### Post date: [31. März 2023 um 08:15 UTC](https://forum.shopware.com/t/check-login-status-in-twig-theme/72117/5 "2023-03-31T08:15:25Z")

</div>

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.
