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

Delimiters

 
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 -> General
View previous topic :: View next topic  
Author Message
JMM
Smarty n00b


Joined: 20 May 2003
Posts: 4

PostPosted: Tue May 20, 2003 4:53 pm    Post subject: Delimiters Reply with quote

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


Joined: 17 May 2003
Posts: 13

PostPosted: Tue May 20, 2003 7:25 pm    Post subject: Reply with quote

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


Joined: 20 May 2003
Posts: 4

PostPosted: Wed May 21, 2003 1:37 pm    Post subject: Reply with quote

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


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Wed May 21, 2003 5:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed May 21, 2003 5:30 pm    Post subject: Reply with quote

Is there a necessary way to change delims that is missing?
Back to top
View user's profile Send private message
JMM
Smarty n00b


Joined: 20 May 2003
Posts: 4

PostPosted: Thu May 22, 2003 1:25 pm    Post subject: Reply with quote

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


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Thu May 22, 2003 2:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu May 22, 2003 6:43 pm    Post subject: Reply with quote

Actually, it does come up a lot, mainly because people do want to switch delimiters every so often.

For more information:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=150
Back to top
View user's profile Send private message
JMM
Smarty n00b


Joined: 20 May 2003
Posts: 4

PostPosted: Thu May 22, 2003 7:32 pm    Post subject: Reply with quote

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


Joined: 24 Jul 2003
Posts: 1
Location: Toronto, Canada

PostPosted: Thu Jul 24, 2003 6:02 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Thu Jul 24, 2003 6:28 pm    Post subject: Reply with quote

I think you could write a prefilter to accomplish that.
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
mysticav
Smarty Rookie


Joined: 19 Sep 2005
Posts: 9

PostPosted: Mon Sep 19, 2005 6:10 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Sep 19, 2005 1:17 pm    Post subject: Reply with quote

mysticav wrote:
Where can I get this extended class ?


You create it. sweatje posted an example further up the page.
Back to top
View user's profile Send private message Visit poster's website
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 -> General 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