Jump to content

Dev on Live Server - Hook to Change Template


DaveP
 Share

Recommended Posts

Having read various posts on dev/staging/prod and ways of editing live pages 'safely', there seems no 'best' way and different folks have their own workarounds.

I am currently extending and improving a live site (not ideal, but it needed to be launched as soon as it was MVP) and it struck me that what would be helpful would be to have a 'dev' version of a template that would be used for logged-in SU like myself, while guests (and maybe other logged-in users) would see 'live' version.

There are good reasons for this approach, not least that setting up https on localhost was horrible last time I tried, plus various other considerations.

Therefore, is it possible to hook (possibly into template render) to change the template file used on a certain page request?

Just to be absolutely clear, what I would like to be able to do is have a live template file called mytemplate.php and another called _dev-mytemplate.php and PW switch between them depending on the user role etc.

Can it be done?

 

Link to comment
Share on other sites

@adrian Perfect! I already had Tracy installed and this works perfectly. Thank you.

For anyone else visiting this thread, you might need to activate Template Path in the Panel Selector of Tracy, create a dev version of the template you want to work on, then navigate to that page and use the Template Path panel as adrian indicates above.

(Small tip from me - make the page header or background a different colour on the dev version, so you know you're on the right one.)

  • Like 3
Link to comment
Share on other sites

4 minutes ago, DaveP said:

(Small tip from me - make the page header or background a different colour on the dev version, so you know you're on the right one.)

Or just trust the color of the template path icon in the Tracy Debug bar:

Red: You have selected a different template file.

Green: You're using the default template file.

Link to comment
Share on other sites

11 minutes ago, adrian said:

Or just trust the color of the template path icon in the Tracy Debug bar:

Red: You have selected a different template file.

Green: You're using the default template file.

I didn't know that, but yeh, that works too. :)

Link to comment
Share on other sites

This morning's commits add to the color scheme:

Red: The current page is using a different template.

Orange: The current page is using it's default template file, but there are other pages on the site that are using a different template file (obviously via the Sticky option). Use "Reset All" to clear this when you're done testing.

Green: All pages on the site are using their default template files.

This is now documented on the blog post.

  • Like 7
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...