I have a PHP site that is backed up by another server, so I have created a file called servername.php, and here are the contents: <?php //Host 1 $servername = "My site name- Server 1"; //Host 2 //$servername = "My site name- Server 2"; ?> PHP: In all my site pages, I simply add the following: include("servername.php"); PHP: Then in the title tag, I insert <?php echo $servername; ?> PHP: That way, if my preferred host goes down, I can update the domain's nameservers and update the $servername in servername.php. It works great! The only problem is that Im not good with smarty, and I have a script installed on my site that uses smarty .tpl files. I need to customize header.tpl to be able to include the above code, so that it displays which server the site is running from. Can someone help me to utilize some sort of PHP include/echo function to do this in my tpl file? HUGE THANKS! +rep
in your php file use: $smarty->assign("servername", $servername); PHP: then, in your .tpl file you can access it with: {$servername} Code (markup):
First, thanks for your help. ***** The file is a .tpl extension, but all the code inside is HTML. Its the header file for a script that utilizes Smarty. This is my php file I use throughout my site: First, I include: include("servername.php"); Code (markup): Then, in the <title> tags I include: <?php echo $servername; ?> Code (markup): This is the content of the actual PHP file: <?php //Server1 $servername = "Server 1"; //Server 2 //$servername = "Server 2"; ?> PHP: Most of my site is in PHP, but I do utilize this script which runs off Smarty syntax. If my primary web host goes down, I can just update my nameservers and update this PHP file to display the secondary servername in the <title> tags of my pages, just to remind me to recheck to see if my primary server is back up. ***** I just need to add the ability to automatically update the <title> using this PHP file within my smarty .tpl file. Hopefully, this makes sense.
How do you display your tpl files on the website? You do also have to remember, that even if you change your nameservers if your host goes down, it will take up to 24-hours to update for all dns servers all around the world, so some users might experience downtime in 24 hours.
Yeah, I know but I use .com and .net, so if the server for .com goes down, I login to godaddy and do a 301 redirect to .net until the server comes back up. I havnt experienced this yet, but Im just taking precautions. Anyway, the header.tpl file is from whmcs. I just want it to echo the contents of a php file for the <title>.
To be honest, I don't have the biggest experience with Smarty. You might try to use ob_start to change your output dynamicly. <?php function changeTitle($buffer) { return (str_replace("<title>Your current title (title that smarty writes)</title>", "<title>".$servername."</title>", $buffer)); } ob_start("changeTitle"); ?> PHP:
Sorry, I was assuming a standard smarty setup.. I don't know anything about WHMCS include('Smarty.class.php'); include("servername.php"); $smarty = new Smarty; // add all your usual PHP code here to do whatever you want to do $smarty->assign('servername', $servername); $smarty->display('templatefile.tpl'); PHP: then in your template file you can do: <title>{$servername}</title> Code (markup):