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

Is it possible to change delimiter temporary by plugin?

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
localhorst
Smarty n00b


Joined: 09 Jul 2018
Posts: 4

PostPosted: Mon Jul 09, 2018 8:43 am    Post subject: Is it possible to change delimiter temporary by plugin? Reply with quote

Hello.
Is there a way to change the default delimiter in a template like this:

Code:

{start_change_delimiter}
[[include 'whatever.tpl']]
[[end_change_delimiter]]
//back to {}


My try above looks like this

Code:

function smarty_function_start_change_delimiter($params)
{
       
//extract($params);
//   unset($params);

    global $smarty;
    $smarty->left_delimiter = '[[';
    $smarty->right_delimiter = ']]';
   
}


... and of course back to {} with the 'end-plugin'.

Greetings mike
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1363

PostPosted: Mon Jul 09, 2018 9:09 am    Post subject: Reply with quote

Of course this is not possible.
Why do you want to do this to begin with?
Back to top
View user's profile Send private message
localhorst
Smarty n00b


Joined: 09 Jul 2018
Posts: 4

PostPosted: Mon Jul 09, 2018 9:24 am    Post subject: Reply with quote

Hello.
Because i use in the templates some js with '{%=file.name%}'.

Instead of changing the whole delimter from {} to something else it would be handy to excude a section in a single or a few templates.

To change it in the logic like this:

Code:

    $smarty->left_delimiter = '[[';
    $smarty->right_delimiter = ']]';
   
    $smarty->display("test.tpl");
    //test.tpl with [[...]]
   
    $smarty->left_delimiter = '{';
    $smarty->right_delimiter = '}';

...works, but seems to me a 'bit ugly'.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1363

PostPosted: Mon Jul 09, 2018 10:21 am    Post subject: Reply with quote

1. Add a space after opening brace to JS code.
2. Wrap JS code in {literal} tags.
3. Include JS from external file.

There's multiple ways to handle it. All of them are explained in the documentation. Did you read it? It even have an explicit note about JS.
Back to top
View user's profile Send private message
localhorst
Smarty n00b


Joined: 09 Jul 2018
Posts: 4

PostPosted: Mon Jul 09, 2018 11:30 am    Post subject: Reply with quote

Yes, I read the part with JS. {literal}, {rdelim}, ... It seems to to be evident this way. But: I also use/need some vars in the JS-part.
So, right now i can choose between

1. changin all delimiters in '<!--[' and ']-->' (works all over the templates)
2. do it in the logic as as already described

better than nothing Confused

Thank you.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1363

PostPosted: Mon Jul 09, 2018 6:15 pm    Post subject: Reply with quote

Option 1 lets you do 99% of the work with little trouble.
I only ever use option 2 for complete inserts, like various trackers/counters.
And of course, I extensively use functions. If you need to repeat the same snippet 30 times through the page with slightly varying parameters, turn it into a function.
Back to top
View user's profile Send private message
localhorst
Smarty n00b


Joined: 09 Jul 2018
Posts: 4

PostPosted: Tue Jul 10, 2018 5:30 am    Post subject: Reply with quote

Thank you Idea
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins 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