Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty XML Tags

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
electr0n
Smarty Rookie


Joined: 26 Mar 2004
Posts: 32
Location: Germany

PostPosted: Fri Jun 11, 2004 3:26 pm    Post subject: Smarty XML Tags Reply with quote

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
View user's profile Send private message
jaceju
Smarty n00b


Joined: 25 Dec 2003
Posts: 3

PostPosted: Mon Oct 04, 2004 1:17 pm    Post subject: Reply with quote

Try this pattern:
Code:
    $pattern = array(
        '!<smarty:([^$][^>]+[^\/])>!',
        '!</smarty:([^>]+[^\/])>!'
    );
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP