ShoeLace1291 Posted January 30, 2009 Share Posted January 30, 2009 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 More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 You didn't actually ask a question.... Are you looking for a template system? Link to comment https://forums.phpfreaks.com/topic/143060-template-variables/#findComment-750281 Share on other sites More sharing options...
ShoeLace1291 Posted January 30, 2009 Author Share Posted January 30, 2009 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 More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 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 More sharing options...
ShoeLace1291 Posted January 30, 2009 Author Share Posted January 30, 2009 the code i used worked with a multidimensional array. array('PAGE_TITLE' => $pagetitle) How would I do that? But I'll see if this works. But yeah you're followin me, gevans. Link to comment https://forums.phpfreaks.com/topic/143060-template-variables/#findComment-750295 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 for a multi-dimensional array use the following <?php $tmp = file_get_content('your-temp-file'); foreach($M_D_ARRAY as $key => $value){ $tmp = str_replace($key, $value, $tmp); } echo $tmp; Link to comment https://forums.phpfreaks.com/topic/143060-template-variables/#findComment-750298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.