leeego Posted July 20, 2013 Share Posted July 20, 2013 (edited) i don't know if this is normal behavior of prestashop, but if i include a line break like this... {l s='i want this text<br/>on a second line'} the br tag will be removed on the frontend. how can i avoid that? Edited July 23, 2013 by leeego (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 20, 2013 Share Posted July 20, 2013 {l s='i want this text'}<br />{l s=';on a second line'} 1 Link to comment Share on other sites More sharing options...
leeego Posted July 20, 2013 Author Share Posted July 20, 2013 i'm aware of that solution, but it's not helping me. because if i need the line break in another language on another position, i can't do it easily. Link to comment Share on other sites More sharing options...
leeego Posted July 21, 2013 Author Share Posted July 21, 2013 so basically, it's not possible to do that? Link to comment Share on other sites More sharing options...
RaPhiuS Posted July 23, 2013 Share Posted July 23, 2013 Hello Leego, Can't you just take the example from vekia and translate your string accordingly in the other language? I don't see what is blocking you here. BR, RaPhiuS Link to comment Share on other sites More sharing options...
leeego Posted July 23, 2013 Author Share Posted July 23, 2013 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 More sharing options...
RaPhiuS Posted July 23, 2013 Share Posted July 23, 2013 I think you have posted this on stackoverflow, but did you actually try this: http://www.smarty.net/docs/en/variable.escape.html.tpl ? Link to comment Share on other sites More sharing options...
leeego Posted July 23, 2013 Author Share Posted July 23, 2013 if i use escape_html, the br tag is converted to <br/> Link to comment Share on other sites More sharing options...
RaPhiuS Posted July 23, 2013 Share Posted July 23, 2013 Ok, I have looked a little bit around and it looks like you would be interested in the following: http://stackoverflow.com/questions/11840349/php-smarty-strip-tag-allow-specific-tags Let us know! Link to comment Share on other sites More sharing options...
leeego Posted July 23, 2013 Author Share Posted July 23, 2013 thanks a lot for your effort, but sadly it doesn't work. the tag still gets removed. {l s='click to<br/>save color'|strip_tags:'<br/>'} Link to comment Share on other sites More sharing options...
vekia Posted July 23, 2013 Share Posted July 23, 2013 but the way above is for variable, not for {l s=''} function 1 Link to comment Share on other sites More sharing options...
RaPhiuS Posted July 23, 2013 Share Posted July 23, 2013 Using " instead of ' in the strip_tags function changes something? Link to comment Share on other sites More sharing options...
leeego Posted July 23, 2013 Author Share Posted July 23, 2013 @raphius: nope, tried it as well. @vekia: is there any other way then to use it in the l function? Link to comment Share on other sites More sharing options...
RaPhiuS Posted July 23, 2013 Share Posted July 23, 2013 As vekia pointed, maybe you can make an export as a variable for your template and try the function call against that exported variable hoping it's not being stripped before? Link to comment Share on other sites More sharing options...
RaPhiuS Posted July 23, 2013 Share Posted July 23, 2013 (edited) 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 July 23, 2013 by RaPhiuS (see edit history) Link to comment Share on other sites More sharing options...
RaPhiuS Posted July 23, 2013 Share Posted July 23, 2013 Did that fix your problem? Link to comment Share on other sites More sharing options...
leeego Posted July 23, 2013 Author Share Posted July 23, 2013 i really appreciate your effort, but this looks like a complex solution for a simple problem. i thought that there must be a simple solution but it doesn't seem to. hmm... Link to comment Share on other sites More sharing options...
RaPhiuS Posted July 24, 2013 Share Posted July 24, 2013 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 More sharing options...
vekia Posted July 24, 2013 Share Posted July 24, 2013 you can also modify the core (modificaiton of function l(); ) but it's a bit harder than suggestions above Link to comment Share on other sites More sharing options...
leeego Posted July 29, 2013 Author Share Posted July 29, 2013 ok, i understand both your points. thanks again for the help, this topic can be closed. Link to comment Share on other sites More sharing options...
Esoterick Posted April 3, 2014 Share Posted April 3, 2014 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 More sharing options...
prestashopninja Posted April 3, 2014 Share Posted April 3, 2014 (edited) This is a programmatical choice and there's a solid reason behind it: The translator isn't the place to deal with XHTML content. This is very neat. What to argue more? Edited April 3, 2014 by prestashopninja (see edit history) Link to comment Share on other sites More sharing options...
Esoterick Posted April 3, 2014 Share Posted April 3, 2014 (edited) 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 April 3, 2014 by Esoterick (see edit history) Link to comment Share on other sites More sharing options...
Salus Posted June 3, 2014 Share Posted June 3, 2014 {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 More sharing options...
shadowless Posted February 27, 2017 Share Posted February 27, 2017 (edited) 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 February 27, 2017 by shadowless (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts