View previous topic :: View next topic |
Author |
Message |
JMM Smarty n00b
Joined: 20 May 2003 Posts: 4
|
Posted: Tue May 20, 2003 4:53 pm Post subject: Delimiters |
|
|
I just started using Smarty today and apparently the delimiters can be changed by setting the left_delimiter / right_delimiter values for a template object or by changing the values in Smarty.class.php. Is that correct, that those are the ways it can be changed. |
|
Back to top |
|
datamile Smarty Rookie
Joined: 17 May 2003 Posts: 13
|
Posted: Tue May 20, 2003 7:25 pm Post subject: |
|
|
Yes it can be changed like that. Just set them before referring to a template
$smarty=new smarty ;
$smarty->left_delimiter='{--'
etc |
|
Back to top |
|
JMM Smarty n00b
Joined: 20 May 2003 Posts: 4
|
Posted: Wed May 21, 2003 1:37 pm Post subject: |
|
|
Yeah, thanks. I know it can be done that way, what I was really wondering is if those are the only two ways it can be done? |
|
Back to top |
|
sweatje Smarty Regular
Joined: 17 Apr 2003 Posts: 70 Location: Bettendorf, Iowa, USA
|
Posted: Wed May 21, 2003 5:24 pm Post subject: |
|
|
I don't know if you consider this a "third" way, but if you often want to redefine the delims, and you also do not want to change the Smarty source, you can:
Code: | class mySmarty extends Smarty
{
function mySmarty() {
$this->left_delimiter='{{';
$this->right_delimiter='}}';
}
}
|
and then use Code: | $smarty = new mySmarty; | instead of Code: | $smarty = new Smarty; |
HTH _________________ Jason
jsweat_php AT yahoo DOT com |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed May 21, 2003 5:30 pm Post subject: |
|
|
Is there a necessary way to change delims that is missing? |
|
Back to top |
|
JMM Smarty n00b
Joined: 20 May 2003 Posts: 4
|
Posted: Thu May 22, 2003 1:25 pm Post subject: |
|
|
Well, the default delimiter is obviously pretty useless for anyone who is using Smarty to generate HTML documents, considering that they often contain CSS or JavaScript.
I don't think it's a very good idea to have to assign different delimiters for every template object. Besides being a hassle, it undermines the idea of having a clearly defined, consistent syntax. Don't get me wrong, I think it's great that you can assign delimiters on a per template basis, but I don't think you should have to do it every time.
Jason's idea is good. I don't think anyone would disagree that it's not a good idea to change the Smarty source to do this. I hadn't thought of that idea, and it wouldn't be a bad way to do it, but what I had actually been thinking is, wouldn't it be good to have two constants for this purpose? SMARTY_LEFT_DELIMITER and SMARTY_RIGHT_DELIMITER. Then you could create a file like this:
Code: |
define( 'SMARTY_LEFT_DELIMITER', '<!--{' );
define( 'SMARTY_RIGHT_DELIMITER', '}-->' );
require_once( 'Smarty.class.php' );
|
and include that in your scripts that use Smarty. |
|
Back to top |
|
sweatje Smarty Regular
Joined: 17 Apr 2003 Posts: 70 Location: Bettendorf, Iowa, USA
|
Posted: Thu May 22, 2003 2:09 pm Post subject: |
|
|
I think the reason this does not come up very often is that people tend towards the "extended class" solution after using Smarty for a while, particularly on multiple projects. It helps for other reasons, like setting up default filters you like, custom delimiters, etc. In my setup, I also include an optional parameter to the constructor to establish some default cache settings.
HTH _________________ Jason
jsweat_php AT yahoo DOT com |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
JMM Smarty n00b
Joined: 20 May 2003 Posts: 4
|
Posted: Thu May 22, 2003 7:32 pm Post subject: |
|
|
Well you have more extensive experience with it than I do. I'm going to use that approach. If it was just the delimiters, the constants would seem like a more appealing solution to me, but given the actual situation -- that there are no such constants, and taking into account the other advantages that you mentioned (that I haven't even considered yet), your solution is better than either of the things that immediately came to my mind.
I think that would be an excellent piece of information for the FAQ.
Thanks Jason. |
|
Back to top |
|
bvr Smarty n00b
Joined: 24 Jul 2003 Posts: 1 Location: Toronto, Canada
|
Posted: Thu Jul 24, 2003 6:02 pm Post subject: |
|
|
Is there a way to define two sets of delimiters? The reason I ask is b/c I use <!--{ }--> which works great with DreamweaverMX in view mode b/c it doesn't show up, and makes it simpe of the designers to work in that view, but if I try to do something like:
<input name="active" type="checkbox" id="active" <!--{ $checked }-->>
Things start to get ugly in the visual mode.
I know it's picky, but it'd be nice if I could use a second delimited like [[ $checked ]] for cases like this.
Alex De Winne |
|
Back to top |
|
sweatje Smarty Regular
Joined: 17 Apr 2003 Posts: 70 Location: Bettendorf, Iowa, USA
|
Posted: Thu Jul 24, 2003 6:28 pm Post subject: |
|
|
I think you could write a prefilter to accomplish that. _________________ Jason
jsweat_php AT yahoo DOT com |
|
Back to top |
|
mysticav Smarty Rookie
Joined: 19 Sep 2005 Posts: 9
|
Posted: Mon Sep 19, 2005 6:10 am Post subject: |
|
|
Quote: | I think the reason this does not come up very often is that people tend towards the "extended class" |
Hi,
Where can I get this extended class ? I'm new to smarty and I would to sit on the right chair from the beginning... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Sep 19, 2005 1:17 pm Post subject: |
|
|
mysticav wrote: | Where can I get this extended class ? |
You create it. sweatje posted an example further up the page. |
|
Back to top |
|
|