|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Jeremy- Smarty Rookie
Joined: 11 Feb 2005 Posts: 16
|
Posted: Fri Feb 11, 2005 2:23 am Post subject: I need help adding a macro replacement system into Smarty |
|
|
I was just recently introduced to Smarty after having tried to create my own templating system. Smarty does everything I could need and more.... except for a functioning macro replacement system. In my system, I have a display class file for my macros... the file looks like this:
$DB->execute( retrieve_cache() );
$cache = $DB->fetch();
class display
{
function html($html)
{
global $cache;
global $INFO;
$macro_array = unserialize($cache['content']);
foreach ($macro_array as $row2)
{
if($row2['allocation'] = "macros")
{
$html = str_ireplace( "<{".$row2['value']."}>", $row2['content'], $html );
}
if($row2['allocation'] = "settings")
{
//echo $row2['content'];
}
}
$html = str_ireplace( "<br>", "<br />", $html );
$html = str_ireplace( "<%title%>", $INFO['site_name'], $html );
$html = str_ireplace( "<%css%>", css($css_id), $html );
$html = str_ireplace( "<%copyright%>", copyright(), $html );
$html = str_ireplace( "<%footer%>", $footer, $html );
echo $html;
}
}
$display = new display;
---------------------
And when I try to call the Smarty system using my class function, it doesn't work.
$display->html( $smarty->display('index.tpl') );
So, no big deal. I figure I can change things around and put the macro replacement system directly into the Smarty class file. I was looking at the fetch() and display functions and can not figure out exactly where the Smarty content is echoed. There are several echo instances for the content and I would just like to know the best way to go about inserting my macro replacement into Smarty itself?
Thanks in advance. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Feb 11, 2005 5:38 am Post subject: |
|
|
In your particular case, I'd suggest you use a prefilter. Technically, you could transform your results prior to sending it to Smarty, but then you would have to write the results to disk first. Another alternative would be to implement your transformation as a resource. Smarty would then apply your tranform any time it retrieved a template through your resource but that is a bit of a bastardization of the resource facility. Here's the quickie on filters:
1) pre-filters patch the template before being processed by Smarty. The patched template is fed to Smarty for compilation.
2) post-filters path the compiled template after Smarty compiles it. The patched output is saved to disk as the compiled template. (not frequently needed)
3) output-filters patch the output generated by running the compiled template through PHP. Its a generated content filter and its results are what are sent back to the client.
see: http://smarty.php.net/manual/en/api.register.prefilter.php |
|
Back to top |
|
Jeremy- Smarty Rookie
Joined: 11 Feb 2005 Posts: 16
|
Posted: Tue Feb 15, 2005 11:24 pm Post subject: |
|
|
Thank you very much. I actually decided to go with using the fetch() function in Smarty to run the returned string through my macro replacement system. It works great. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|