diogo Posted January 4, 2013 Share Posted January 4, 2013 A very simple tip, but that might be useful for someone that didn't think of it... This is what I usually do if I want to change something on a live site. if($user->name!='diogo'){ // live code }else{ // my new code } Like this I'm the only one that sees the changes. More examples: // test new javascript. do the same for styles <?php if ($user->name!='diogo'){?> <script src="<?php echo $config->urls->templates?>scripts/main.js"></script> <?php }else{?> <script src="<?php echo $config->urls->templates?>scripts/main-dev.js"></script> <?php }?> // test new head file if($user->name!='diogo'){ include(head.inc); }else{ include(head-dev.inc): } and so on... edit: corrected the first block by Nik's suggestion 15 Link to comment Share on other sites More sharing options...
Luis Posted January 4, 2013 Share Posted January 4, 2013 Nice, very handy for my next project Link to comment Share on other sites More sharing options...
MatthewSchenker Posted January 4, 2013 Share Posted January 4, 2013 Greetings diogo, Excellent idea. This got me thinking... It seems the concept could be expanded systamatically. I'm still working it out, but I'm imagining a system that detects development/testing elements. Maybe a way to tag certain CSS classes/IDs and place development JQuery plugins inside a specified folder? Then you could have a ProcessWire conditional that checks to see if certain CSS is present, or if there are any JQuery plugins inside that specified folder. If yes, the developer elements would happen; if no, then the "regular" site elements happen. I like this! Thanks, Matthew 1 Link to comment Share on other sites More sharing options...
nik Posted January 4, 2013 Share Posted January 4, 2013 if($user->name!='diogo'){ // my new code }else{ // live code } Sorry, I just have to point this out: don't you have the blocks here the wrong way around? Everyone probably gets the point and corrects this automatically though - as you did with the latter examples yourself . Unless they just copy and paste the first snippet and go from there... 4 Link to comment Share on other sites More sharing options...
diogo Posted January 4, 2013 Author Share Posted January 4, 2013 @Nik, you are right of course. Already changed it. @Matthew, seems interesting but I really like to keep it simple and adapted to each situations need. What you are asking can be closely achieved by creating a "dev" folder inside the templates folder and copying there your styles and scripts folders. Then, put this line on the top your header.php: if ($user->name == 'me') $config->urls->templates .= "dev/"; 4 Link to comment Share on other sites More sharing options...
Joss Posted January 5, 2013 Share Posted January 5, 2013 Sounds like one of those snippets that would be useful in Sublime.... Link to comment Share on other sites More sharing options...
Pete Posted January 5, 2013 Share Posted January 5, 2013 I do the exact same as this quite a lot - obviously if you're tweaking things on a live site a lot and there are lots of visitors it's not ideal as if someone loads the page when you're just uploading a template change and you're doing this quite a lot they'll possibly get an error. I'm doing it all the time on a site at the mo though as it's not open yet - it's in maintenance mode anyway using my module (cheap plug ). 2 Link to comment Share on other sites More sharing options...
diogo Posted January 6, 2013 Author Share Posted January 6, 2013 The reason I like these kind of snippets so much is the freedom they offer. If you want to show the dev page to anyone that is logged in, change the conditional to: if($user->name='guest') If you want to give a special url like domain.com/?version=dev change it to: if($input->get->version!='dev') with the url version you can also make all the links work wth sessions like this: if($input->get->version!='dev' OR $session->version != 'dev') and inside the else: $session->version = 'dev'; 7 Link to comment Share on other sites More sharing options...
Can Posted July 8, 2014 Share Posted July 8, 2014 Pete, in this case you could include a file conditionally like with the "head-dev.inc" diogo mentioned so your changing the main template only once oh, pretty old here..but maybe still helpful for someone Link to comment Share on other sites More sharing options...
msummers Posted October 31, 2015 Share Posted October 31, 2015 I realize this thread is beyond old, but I have a related question. I want to bring up a new domain name and migrate my dev site to it, but I don't want it to be visible to the public yet. What I would like to have is a "COMING SOON" image shown to everyone who browses into that domain (the domain name has already been published by the client), yet still allow those 'in the know' to peruse the entire dev site. I can do this by sniffing for the IP address of the visitor, right? Would something like this work in head.inc? <?php $allowed = array('ip address 1', 'ip address 2', etc); if (!in_array($_SERVER['HTTP_CLIENT_IP']), $allowed) { header("Location: http://example.com/maintenance.html"); exit(); } ?> Link to comment Share on other sites More sharing options...
SteveB Posted October 31, 2015 Share Posted October 31, 2015 You could setup users for the "in the know people" and require them to login at /processwire/login/ (default). if(!$user->isLoggedin()){ $this->session->redirect("http://example.com/maintenance.htm");} Set them up with a role that has only view privilege and they can't hurt anything. Link to comment Share on other sites More sharing options...
LostKobrakai Posted October 31, 2015 Share Posted October 31, 2015 There's even the maintenance module by pete, where you can setup a raw html page to be shown for guest users. 1 Link to comment Share on other sites More sharing options...
msummers Posted October 31, 2015 Share Posted October 31, 2015 I've looked at the module, and I'd like it to be more passive than that. Plus, instead of confronting visitors with a login screen, I'd rather give them some information. In fact, this code in head.inc seems to work nicely - $allowed = array('192.168.1.0','192.168.1.1');$ip = $_SERVER['REMOTE_ADDR'];if (!in_array($ip, $allowed)) { header("Location: http://example.com/maintenance.html"); exit();} 2 Link to comment Share on other sites More sharing options...
tooth-paste Posted February 21, 2016 Share Posted February 21, 2016 if($user->name!='diogo'){ include(head.inc); }else{ include(head-dev.inc): } I want to use this line of code (great tip btw). I'am a Mac user and the strange thing is that it doesn't work in Safari. Has anyone have the same experience? Link to comment Share on other sites More sharing options...
Jan Romero Posted February 21, 2016 Share Posted February 21, 2016 Try clearing your browser cache or force-refresh the page using CMD+SHIFT+R (I think). Link to comment Share on other sites More sharing options...
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