Jump to content

Help with template


Arimak

Recommended Posts

This is more of a basic code-reuse question, but what I've got is:

 

function LoadTemplate($template, $title, $main)
{
/*dbg*/ WriteToLog("INFO: LoadTemplate()");
/*enddbg*/
$template = stripslashes($template);
$template = eregi_replace('{title}', $title, $template);
$template = eregi_replace('{main}', $main, $template);

/*dbg*/ WriteToLog("   INFO: Replaced tags: {title}, {main}");
return $template;
}

 

What I'd like to do is be able to replace an undetermined number of tags with dynamic content.

 

I'm still very new to PHP, so how to do something simple like this is still elusive to me.

Link to comment
https://forums.phpfreaks.com/topic/100551-help-with-template/
Share on other sites

Here's what I do:

 

$homeDir = "/home/username/";
$domain = "mydomain.com";
include($homeDir . "includes/comm_config.inc");
$ct = file_get_contents($homeDir . "includes/template.html");
$css = file_get_contents($homeDir . "public_html/css/styles.css");
$ct = str_replace("%css_file%", "<style>" . $css . "</style>", $ct);
$header = substr($ct, 0, stripos($ct,"%main_area%"));

$footer = substr($ct, stripos($ct,"%main_area%")+11);


echo $header;
echo "This is my content.";
echo $footer;

 

Then in my template file, I have %css% in the header area, and %main_area% in--you guessed it--the main content area.

Link to comment
https://forums.phpfreaks.com/topic/100551-help-with-template/#findComment-514392
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.