Switch frontend template for admins only

Merchant
From United Kingdom
Member since apr. 2023

I am working on a new front end template but I was wondering if there was a setting somewhere so only the admin could see the new template on the front end.

Moderator
From Lithuania
Member since mar. 2016

No, you can only turn shop into development mode.

One way of doing this is to create a development environment while you work on the template and only transfer when it's done. This addon is extremely good: [url=https://www.litecart.net/en/addons/33/develop-and-deploy]https://www.litecart.net/en/addons/33/develop-and-deploy[/url]

It allows not only template, but any kind of modifications to be done in dev shop and then transferred in a single click.

Another way is to make template on your local computer and then transfer when it's done.

tim
Founder
From Sweden
Member since mai 2013
tim

You could produce an if condition.


  document::$template = 'new.catalog';
}```

But for these reasons it's better to set up a development platform where you can experiment freely.

1. Setup a new domain dev.domain.com
2. Copy the production database to a new database.
3. Copy all the files to the dev domain.
4. Adjust some configs https://wiki.litecart.net/how_to_move_the_platform
5. Go to Admin -> Settings -> Listing and enable Development Mode
6. Don't underestimate the power of this addon. https://www.litecart.net/en/addons/33/develop-and-deploy
Merchant
From United Kingdom
Member since apr. 2023

Thanks for the replies guys. I’ll take your advice and setup a development site. Cheers

Merchant
From United Kingdom
Member since apr. 2023

Hi Tim I have setup a development site to work on my template but I would also like to explore your previous suggestion:

You could produce an if condition.

if (!empty(user::$data['id'])) {
  document::$template = 'new.catalog';
}

Could you please tell me which file I would put this code.

Thanks

Merchant
From United Kingdom
Member since apr. 2023

Actually I have just put that code at the top of index.php and it works a charm when I sign in to the admin backend then browse to the front end the new template appears. I then browsed to the site from other devices and the old original appears. perfect. Thank you Tim.

 I put your code under:

require_once('includes/app_header.inc.php');

  if (!empty(user::$data['id'])) {
    document::$template = 'pos.catalog';
  }

tim
Founder
From Sweden
Member since mai 2013
tim

Indeed the code works from anywhere :)

Merchant
From United Kingdom
Member since apr. 2023

If anyone try's to use Tim's suggestion of using:

if (!empty(user::$data['id'])) {
    document::$template = 'pos.catalog';
  }

I found that I needed to clear the cache in litecart settings because the new template didn't load the css. I've got no idea why, probably something simple i overlooked or maybe because i placed the code in index.php. But clearing the cache solved the problem.

Merchant
From United Kingdom
Member since apr. 2023

Hi Tim. Sorry if this is a silly question (I'm Learning). but I would like to try and understand your code better.

    document::$template = 'new.catalog';
  }

Am I right in saying this code snippet should work for the admin only or any logged in user?

tim
Founder
From Sweden
Member since mai 2013
tim

The user node holds the backend user ID if the user is logged in. So by producing this condition checking if it's not empty you are making sure the backend user is logged in or not. document::$template holds the setting of the current template.

To do the same for customers it's the following:
 if (!empty(customer::$data['id']) {

You
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.