View previous topic :: View next topic |
Author |
Message |
localhorst Smarty n00b
Joined: 09 Jul 2018 Posts: 4
|
Posted: Mon Jul 09, 2018 8:43 am Post subject: Is it possible to change delimiter temporary by plugin? |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jul 09, 2018 9:09 am Post subject: |
|
|
Of course this is not possible.
Why do you want to do this to begin with? |
|
Back to top |
|
localhorst Smarty n00b
Joined: 09 Jul 2018 Posts: 4
|
Posted: Mon Jul 09, 2018 9:24 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jul 09, 2018 10:21 am Post subject: |
|
|
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 |
|
localhorst Smarty n00b
Joined: 09 Jul 2018 Posts: 4
|
Posted: Mon Jul 09, 2018 11:30 am Post subject: |
|
|
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
Thank you. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jul 09, 2018 6:15 pm Post subject: |
|
|
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 |
|
localhorst Smarty n00b
Joined: 09 Jul 2018 Posts: 4
|
Posted: Tue Jul 10, 2018 5:30 am Post subject: |
|
|
Thank you |
|
Back to top |
|
|