Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty: How to display "{" and "}" special characters

lets say I have a smarty variable TAKEN FROM DATABASE called

$myvar = "i am very happy {-: "

if I try to display it, it gave me "500 Internal Errors" because the string contains "{" character which is used by smarty. since its from the database, I dont have any control on the values it will give me... what I noticed if the string contains those characters it gives me error.

how can i display the spacial charater correctly without causing this errors? Hope somebody can help!

like image 342
Chinchan Zu Avatar asked Dec 29 '25 07:12

Chinchan Zu


2 Answers

literal is not a good way to use it

{ldelim} for {
{rdelim} for }

is a good choice if you want to use them.

For example if you want to send a json like below

send('[{'ID':1},{'Answer':'A'}]');

the code will be like this in tpl file:

send('[{ldelim}'ID':{$smarty.session.user_id}{rdelim},{ldelim}'Answer':'A'{rdelim}]');
like image 110
Alp Altunel Avatar answered Dec 30 '25 22:12

Alp Altunel


Try outputting your data between{literal} {/literal} tags. See {literal} Smarty documentation.

like image 23
Edd Avatar answered Dec 30 '25 23:12

Edd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!