Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Shopify, theme Expanse.
I have two index templates - index.json and index.logged.json. And I want the site user to be redirected to index.logged.json if that user is logged in. I know how to verify the user:
{% if customer %} ... {%- endif -%}
But how do I display index.logged.json if that user is logged in? Where should I write this condition?
Please help.
Solved! Go to the solution
This is an accepted solution.
Hi @max_max_max
Access two different index templates you just need to add below script in theme.liquid file.
<script>
{%- if customer -%}
let template = '{{ template }}';
let url = window.location.href;
let shopurl = '{{ shop.url }}';
if(template == 'index' && !(url.includes('?view=logged'))){
document.location.href = shopurl + "?view=logged";
}
{%- endif -%}
</script>
You can also add/edit/remove section in new index template from CMS.
I hope that this will help you to fulfil your requirements.
Happy coding!!
This is an accepted solution.
Hi @max_max_max
Access two different index templates you just need to add below script in theme.liquid file.
<script>
{%- if customer -%}
let template = '{{ template }}';
let url = window.location.href;
let shopurl = '{{ shop.url }}';
if(template == 'index' && !(url.includes('?view=logged'))){
document.location.href = shopurl + "?view=logged";
}
{%- endif -%}
</script>
You can also add/edit/remove section in new index template from CMS.
I hope that this will help you to fulfil your requirements.
Happy coding!!
I did it differently, but my solution is similar to yours!
Thanks you! 🙂
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025