DaveP Posted June 21, 2016 Posted June 21, 2016 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?
adrian Posted June 21, 2016 Posted June 21, 2016 Tracy to the rescue: https://processwire.com/blog/posts/introducing-tracy-debugger/#template-path-panel or you could place something like this in your site/ready.php file: if($user ......) { $page->template->filename = '_dev-' . $page->template->filename; } else { } 7
DaveP Posted June 21, 2016 Author Posted June 21, 2016 @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.) 3
adrian Posted June 21, 2016 Posted June 21, 2016 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.
DaveP Posted June 21, 2016 Author Posted June 21, 2016 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.
adrian Posted June 21, 2016 Posted June 21, 2016 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. 7
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now