|
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 |
electr0n Smarty Rookie
Joined: 26 Mar 2004 Posts: 32 Location: Germany
|
Posted: Fri Jun 11, 2004 3:26 pm Post subject: Smarty XML Tags |
|
|
It was a task of my teacher and I wanted to post it here. It's not realy XML compliant, but others ways are not dynamic.
You have to set the $left_delimiter to "<smarty:" and the $right_delimiter to "/>".
plugins/prefilter.xml_tags.php
[php:1:2f8bd8ba5f]<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: prefilter.xml_tags.php
* Type: prefilter
* Name: xml_tags
* Purpose: To make Smarty more xmlish ;)
* -------------------------------------------------------------
*
* @param string $source
*
* @access private
* @return string
*/
function smarty_prefilter_xml_tags($source)
{
$pattern = array(
'!<smarty:([^$][^>]+)>!',
'!</smarty:([^>]+)>!'
);
$matchs = array(
'<smarty:\\1/>',
'<smarty:/\\1/>'
);
$source = preg_replace($pattern, $matchs, $source);
return $source;
}
?>[/php:1:2f8bd8ba5f]
Template can look like that:
Code: | <smarty:$variable/>
<smarty:section loop=$loopvar name=sec1>
<smarty:$loopvar[sec1]/>
</smarty:section>
<smarty:include file=success.tpl/> |
Before using display() you have to load this prefilter ($smarty->load_filter('pre', 'xml_tags');) or set it to the autoload_filters ($smarty->autoload_filters = array('pre' => array('xml_tags'));).
cheers, |
|
Back to top |
|
jaceju Smarty n00b
Joined: 25 Dec 2003 Posts: 3
|
Posted: Mon Oct 04, 2004 1:17 pm Post subject: |
|
|
Try this pattern:
Code: | $pattern = array(
'!<smarty:([^$][^>]+[^\/])>!',
'!</smarty:([^>]+[^\/])>!'
);
|
|
|
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
|