Switch frontend template for admins only

Merchant
Från United Kingdom
Medlem sedan 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
Från Lithuania
Medlem sedan mars 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
Från Sweden
Medlem sedan maj 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
Från United Kingdom
Medlem sedan apr. 2023

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

Merchant
Från United Kingdom
Medlem sedan 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
Från United Kingdom
Medlem sedan 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
Från Sweden
Medlem sedan maj 2013
tim

Indeed the code works from anywhere :)

Merchant
Från United Kingdom
Medlem sedan 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
Från United Kingdom
Medlem sedan 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
Från Sweden
Medlem sedan maj 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']) {

Du
Denna webbplats använder inga kakor och ingen spårningsteknik från tredje part . Vi tror att vi kan göra det bättre än andra och tänker verkligen på din integritet.