Restrict a page to only logged in users - (2.0) Dawn theme

SKRASTS
Excursionist
25 0 4

I want to make a certain page hidden unless the user is logged in without an app. I've seen the code that has been posted (below), but I am not sure where to put the code in the 2.0 theme. Here is what I've tried:

  • Adding it to the "Custom Liquid" section that I can add to the page - but it is not quiteright since I want to hide the entire page.
  • Adding it to the page code itself page.wholesale.json, but it gives me errors and won't save.
  • Adding it to the Content section on the Page itself (under Sales Channels) but that doesn't work.

Here is what I'm working with:

{% if customer %}
THE ENTIRE PAGE CONTENTS
{% else %}

This page is restricted to wholesale customers.

{% endif %}

Replies 6 (6)

PaulNewton
Shopify Partner
6338 578 1343

Hi @SKRASTS it's not in page.wholesale.json as that is a JSON template file not a liquid file.

The json references the liquid templates it does use allowing for the new dynamic sections system in OS2.0 . 

For dawn based themes the liquid template would be main-page.liquid 

https://github.com/Shopify/dawn/blob/main/templates/page.json#L4 

For third party themes you may need to figure out what templates page.wholesale.json references. 

 

If you still can't find it and need direct support you can contact me at paull.newton+shopifyforums@gmail.com so I have context please provide store url, theme name, and problem description or post-url. 

 

  • Adding it to the Content section on the Page itself (under Sales Channels) but that doesn't work.

Assuming you mean the online-sales channel, keep in mind other channels may expose products or content if they have access to it by being published as they do not use a stores theme logic for content control.

 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


SKRASTS
Excursionist
25 0 4

Okay, my page uses the main-page.liquid.

 

If I add it there though, all the pages that use that main-page.liquid will need to be logged in, right?

 

Should I duplicate that main-page and call it customer-page.liquid and reference that liquid file with the .json file?

PaulNewton
Shopify Partner
6338 578 1343
Should I duplicate that main-page and call it customer-page.liquid and reference that liquid file with the .json file?

Basically yes; or name it main-page-wholesale.liquid , or main-page-customer.liquid etc to maintain consistency.

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


BonzaDogTreats
Shopify Partner
96 1 17

Hi Paul

Just stumbled across this and wondered if you could help please. I'm using Dawn and want to limit everyone to the home page unless they are logged in. I've worked out how prevent customers from creating their own accounts, but not sure how to stop visitors from moving around the website. As this is a single product website, I'm hoping to do this with coding rather than app.

Thanks for any help.

PaulNewton
Shopify Partner
6338 578 1343

@BonzaDogTreats just use the code wrapping it around for the entire part of the site content you want to now show in theme.liquid

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


Jahid-KlinKode
Excursionist
145 1 4

Hi @SKRASTS, looking to limit access to certain products or pages on your Shopify store? This video guide has the answers: