Jump to content

Template Variables


ShoeLace1291

Recommended Posts

I remember using a code that passes PHP variables to template files so you don't have to include PHP tags in them.  You know, like using "Welcome back, USER_NAME"  and user_name would output as whatever the user's login name is.  I had the code a long time ago but I stopped coding and forgot how to do it.

Link to comment
https://forums.phpfreaks.com/topic/143060-template-variables/
Share on other sites

How would I pass a variable to a template file without using PHP tags in the template file?  I know it involved arrays and file_get_contents.

 

Example:

<HTML>
<TITLE>PAGE_TITLE</TITLE>
<link rel='stylesheet' href='STYLE_HREF'>

 

In the main file you would set page_title and style_href with arrays and use file_get_contents to pass those variables to the template file.  I just forget exactly how to do it.

Link to comment
https://forums.phpfreaks.com/topic/143060-template-variables/#findComment-750287
Share on other sites

I'm following you;

 

<?php
$tmp = file_get_content('your-temp-file');
$search = array('PAGE_TITLE', 'STYLE_HREF');//an array of you template presets like - PAGE_TITLE, STYLE_HREF
$replace = array('page title to use', 'default.css');//actual values in the same order
$changedTMP = str_replace($search, $replace, $tmp);
echo $changedTMP;

Link to comment
https://forums.phpfreaks.com/topic/143060-template-variables/#findComment-750292
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.