Jump to content

<br/> inside smarty string ignored


Recommended Posts

i could live with that answer - although i think it's not a nice one - if one could at least tell me if it is or isn't possible to have a <br> within the string (and if not, why not). vekia posted his answer without any comment

Link to comment
Share on other sites

Ok I found a way for you to do it and to not get it stripped:

 

For example, assuming you are in a controller you could call:

 

$this->context->smarty->assign('test',$this->module->l('Settings <br> updated'));

 

The <br> tag got not stripped when exported, add {debug} to verify this.

 

You could then use this variable in your template, and the l() call in the controller would guarantee your translation is exported appropriately.

 

Not very efficient but works, I tested it just right now.

 

And you don't need the strip_tags function. Just regular call to {$test} in this example.

Edited by RaPhiuS (see edit history)
Link to comment
Share on other sites

I don't think you will find another solution and what I did above is not a complex solution. It's exactly the same, except you build your string in PHP instead of the template file.

 

Ultimately, your translations are not affected since it uses the l() method so I would rather say that it's exactly the same, just in PHP instead of Smarty and will smoothly integrate with PrestaShop.

 

Anyway it's your call! ;-)

Link to comment
Share on other sites

  • 8 months later...

I had the same problem, to resolve it I used the js="true" option in my template file.

The "L" smarty function calls the smartyTranslate function and that function invokes the methods TranslateCore::getModuleTranslation or TranslateCore::getAdminTranslation .

In both case, if the $js parameter equals true, addslashes is called rather than htmlspecialchars.

So if you set js to true your markup is kept. However some slashes may appear. To remove them simply use stripslahes.

{capture assign="myTranslation"}
{l s='I\'m <strong>%d</strong> year old.<br/>And you?' js="true" mod='mymodule' sprintf=[22] }
{/capture}
<p>{$myTranslation|stripslashes}</p>
Link to comment
Share on other sites

I understand the reason why Prestashop are dealing markups in locales this way. 

But sometime, very reasonable theoretical choices are hard to apply practically.

Like with the following example.

{capture assign="discountLocale"}
{l s='Get a <strong>%1$s discount</strong> with the following payment methods: <strong>%2$s</strong>. The new grand total will be <strong>%3$s</strong>.'
js="true" mod='discountbypayment' sprintf=[$discount.amount, $discount.methods, $discount.total] }
{/capture}
<p>{$discountLocale|stripslashes}</p>

I understand that this is just a convenient "hack".

Edited by Esoterick (see edit history)
Link to comment
Share on other sites

  • 1 month later...
{l s='i want this text'}<br />{l s=';on a second line'}

Thanks vekia, worked for me perfectly. Was looking for this thing for a long while. It's only a matter of smarty syntax, which I DONT KNOW, AND .tpl'S WILL KILLME  :)

Link to comment
Share on other sites

  • 2 years later...

I has similar issue ( my string must have <br>) and this one working for me:

 

Change your line with variable like:

{$feature.value|escape:'html':'UTF-8'}

to:

{html_entity_decode($feature.value)}

 

and in string replace <br /> with <br />

 

I hope, it will be helpfull for anybody.

Edited by shadowless (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...