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! 🙂
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025