Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

two diferent delimiter
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
TimJim
Smarty Rookie


Joined: 22 Apr 2003
Posts: 14
Location: Germany

PostPosted: Mon May 05, 2003 9:05 pm    Post subject: two diferent delimiter Reply with quote

before i used HTML_Template_IT of the PEAR project. There the blocks (here: sections) use the delimiter <!-- BEGIN asdf ---> and <!-- END asdf --> and the placeholder of the variables look like {placeholder}.

It would be very helpful for the HTML Designers if the sections could have been a delimiter beginning with <!-- and the variables could have a diferent delimiter like {

What advantage has this?
A lot of times the sections are used for table rows or data cells. That's why the sections are in a part of the HTML structure where can't be any shown text. If the delimiter of the sections begin with <!-- I can open the template file (which I name usually *.html) with any Browser or HTML Editor. Like this the sections tags are not shown, but the variables are shown like {$variable}. I think this would be a great advantage, because the programmer can pass the edited template to the HTML designer and he can work with it like ever.

What do you think of this? There only have to been allowed to diferent delimiter. I would prefer <!--{ }--> and { } as standard.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon May 05, 2003 9:28 pm    Post subject: Reply with quote

grow your own. Smile

see: http://smarty.php.net/manual/en/advanced.features.prefilters.php
a prefilter is a php-function that squeezes your template to suit your needs before it is handed out to the compiler.

it should be pretty easy to write a pre-filter that collapses "<!--{" to "{" and "}-->" to "}".

have fun
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TimJim
Smarty Rookie


Joined: 22 Apr 2003
Posts: 14
Location: Germany

PostPosted: Mon May 05, 2003 9:42 pm    Post subject: Reply with quote

Oh... it's that easy? Yeah thanks, think this will be no problem.

But in general, you don't like the idea to be implemented? When I changed from a very, very simple template system to HTML_Template_IT this was one of the "wow"-features for me and changing to Smarty the only feature I have missed.

I thought the idea of a template sytem is, that the HTML designer can work independet without understanding the develop side. But how can a HTML designer work good, when he doesn't even can open an template file without displaying all kind of codes in parts where they don't belong to (a section tag between two table rows will be shown before the whole table).
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon May 05, 2003 10:03 pm    Post subject: Reply with quote

oh yes, i like the idea in general. i have no competence in deciding how useful this is since i am not a html-editor-user, but it sounds like a neat trick.

if this is useful it has definately a place in the contrib-repository:
http://smarty.php.net/contribs.php or on the plugins-page of the wiki
http://smarty.incutio.com/?page=SmartyPlugins

if more people find it useful, it may be incorporated in the distribution, no problem in general. but i like it more if it is not a core feature (that extends smarty's syntax a bit unnecessarily) but a filter. like trimwhitespace for example, it's a thing many people find useful, but it is not a configuration-flag in smarty, it's an output-filter that comes with the distribution.

this way it is guaranteed, that people who have no need for it, don't have to cope with it, and others who like it, don't have much work in using it (just add it to your $autoload_filters when initialising smarty).

that's all about why i suggest a pre-filter.

greetings
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dennisthemenace
Smarty Rookie


Joined: 31 Jul 2003
Posts: 5
Location: london

PostPosted: Mon Aug 04, 2003 1:29 pm    Post subject: Reply with quote

Hello

We are newbie to smarty and are html designers rather than php. Did this get implemented and can I download it as I am looking for a way to display the delimiters differently for our designers ?

Thanks

Paul
Back to top
View user's profile Send private message Visit poster's website
Claas
Smarty n00b


Joined: 25 Nov 2003
Posts: 1

PostPosted: Tue Nov 25, 2003 1:13 pm    Post subject: Pre filter not as good as ... Reply with quote

Hi,
i did what you suggestet, and wrote my own prefilter

function smarty_prefilter_delimiters(&$smarty,$code){
$ld = $smarty->left_delimiter;
$rd = $smarty->right_delimiter;
return preg_replace("#<\!--($ld.?$ld)-->#U",'\1',$code);
}

works fine so far but:
prefilter is done before {include} subtitution.
so the prefilter doesnt work in included files.

My suggestion: let $stmarty->left_delimiter be an array (or String to be backward compatible) an use it in the expression as or.

Please be kind, im not a native english speaker.

Claas
Back to top
View user's profile Send private message
sucresemoule
Smarty n00b


Joined: 28 Oct 2003
Posts: 2

PostPosted: Tue Jan 13, 2004 2:34 pm    Post subject: Re: two diferent delimiter Reply with quote

I think this would be a great idea.
I made several sites with smarty. For the last one i choose <% %> as delimiters. { } is very annoying because of the javascripts et the css. And when you use a lot of section, it is a real mess with dreamweaver.

We should be able to use { } for values and something like <% or <? or <!-- for controls parts like if and sections.


TimJim wrote:
before i used HTML_Template_IT of the PEAR project. There the blocks (here: sections) use the delimiter <!-- BEGIN asdf ---> and <!-- END asdf --> and the placeholder of the variables look like {placeholder}.

It would be very helpful for the HTML Designers if the sections could have been a delimiter beginning with <!-- and the variables could have a diferent delimiter like {

What advantage has this?
A lot of times the sections are used for table rows or data cells. That's why the sections are in a part of the HTML structure where can't be any shown text. If the delimiter of the sections begin with <!-- I can open the template file (which I name usually *.html) with any Browser or HTML Editor. Like this the sections tags are not shown, but the variables are shown like {$variable}. I think this would be a great advantage, because the programmer can pass the edited template to the HTML designer and he can work with it like ever.

What do you think of this? There only have to been allowed to diferent delimiter. I would prefer <!--{ }--> and { } as standard.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Feb 07, 2004 9:54 pm    Post subject: Reply with quote

I took this a little further and wrote a prefilter that enables "<" and ">" as delimiters.

It looks for "<* ...>" and if "*" is a valid smarty-tag it replaces it by "{* ...}". So something like this works:
Code:

<foreach from=$rows item="cell">
<tr>
    <td>{$cell}</td>
</tr>
</foreach>


Is this in any way useful or just raising confusion?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
wintermute
Smarty n00b


Joined: 23 Feb 2004
Posts: 4

PostPosted: Mon Feb 23, 2004 8:20 am    Post subject: Reply with quote

messju wrote:
I took this a little further and wrote a prefilter that enables "<" and ">" as delimiters.

It looks for "<* ...>" and if "*" is a valid smarty-tag it replaces it by "{* ...}". So something like this works:
Code:

<foreach from=$rows item="cell">
<tr>
    <td>{$cell}</td>
</tr>
</foreach>


Is this in any way useful or just raising confusion?


Its usefull for me, cos' template editors don't think that they have to learn a new markup-language... they'll think that they edit an extended version of html ;) Scary for me, but nice for them.

Where can i find this prefilter?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Feb 24, 2004 10:07 am    Post subject: Reply with quote

I put it here: http://lammfellpuschen.de/html_delimiters/
Tell me if it works for you, i will try to support it and/or you with it.


Last edited by messju on Mon Mar 03, 2008 1:08 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Tue Feb 24, 2004 1:35 pm    Post subject: Reply with quote

Quote:
I put it here: http://lammfellpuschen.de/html_delimiters/


Very nice Smile

I like this approach because it integrates very nice. But there's still the problem with designers always using "{" or "}" instead of "{ldelim}" or "{rdelim}" Twisted Evil
Perhaps your prefilter should be enhanced to silently replace all "{" and "}" if their content dont match a smarty variable "{$[a-zA-Z] ... }". Then they could simply write code like this:
Code:

  <script type="text/javascript">
    function foo() {
      alert('{$bar}');
    }
  </script>


Good or bad idea?! Confused
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Feb 24, 2004 1:51 pm    Post subject: Reply with quote

@andré: I don't know if that's good or bad. The simplest solution is to change $smarty->left- and -right_delimiter to something less clashing than "{,}", maybe "<%,%>". The prefilter above is capable of handling that and your example would work as:

Code:
<script type="text/javascript">
    function foo() {
      alert('<% $bar %>');
    }
</script>


I think it's not as simple as just looking for "{$[a-zA-Z] ... }".
{#config_var#}
{"foo"|strtoupper}
{* -{*- *}
and maybe other things have to be handled accordingly.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
wintermute
Smarty n00b


Joined: 23 Feb 2004
Posts: 4

PostPosted: Tue Feb 24, 2004 7:12 pm    Post subject: Reply with quote

messju wrote:
I put it here: http://lammfellpuschen.de/html_delimiters/
Tell me if it works for you, i will try to support it and/or you with it.


Thanks a lot, i'll read and test the plug and give you feedback. But now i'll watch soccer ;)
Back to top
View user's profile Send private message
wintermute
Smarty n00b


Joined: 23 Feb 2004
Posts: 4

PostPosted: Tue Feb 24, 2004 11:14 pm    Post subject: 1:1 Reply with quote

editing the prefilter everytime i write a plugin is redundant, cos' the info of available plugins must be already somewhere in the system.

i always thought the smarty-class holds all plugins available inside one property ($smarty->_plugins) but now, trying to make messjus prefilter more dynamic, i realised that $smarty->_plugins gets only filled with the plugins while parsing a template. prefilters have no idea about the plugins inside a template without hacking the code.

so what do i need? a method that returns and/or sets all available functions.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Feb 24, 2004 11:21 pm    Post subject: Reply with quote

you don't have to edit the prefilter. the prefilter should look for the plugins on demand. anything that is not a plugin is considered a html-tag.

if you are irritated by this:
[php:1:916d696d1e] /* these are not replaced */
'a' => 'html',
'form' => 'html',[/php:1:916d696d1e]

That's just because I have a block.a.php and a block.form.php in one of my projects, but I want the prefilter to ignore <a> and <form> and *dont* smartify them.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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