Note that there are some explanatory texts on larger screens.

plurals
  1. POUnexpected token on like breaks (smarty + ajax)
    primarykey
    data
    text
    <p>I need to output a couple of lines of escaped html using ajax, with the object being generated by smarty. However, I keep getting unexpected token even if I used both nl2br and </p> <pre><code>|regex_replace:'/[\r\n]/' : '&lt;br/&gt;'. </code></pre> <p>Here is the troublesome code:</p> <pre><code>"value": "&amp;lt;div class=&amp;quot;ps-header-links&amp;quot;&amp;gt;&lt;br/&gt; &lt;br/&gt; &amp;lt;ul&amp;gt;&lt;br/&gt; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://prestashop.com&amp;quot; title=&amp;quot;some title&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;icon-small helpicon&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;English&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br/&gt; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;dsjfsiodf&amp;quot; title=&amp;quot;link2title&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;icon-small helpicon&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Link 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br/&gt; &amp;lt;/ul&amp;gt; &lt;br/&gt; &amp;lt;/div&amp;gt;", </code></pre> <p>And here is what I used on the smarty template:</p> <pre><code>"value": "{$data.value|addslashes|regex_replace:'/[\r\n]/' : '&lt;br/&gt;'}", </code></pre> <p>Any idea of what I am doing wrong? The original html(escaped using htmlspecialchars as I only need a visual representation):</p> <pre><code> : &amp;lt;div class="ps-header-links"&amp;gt; &amp;lt;ul&amp;gt; &amp;lt;li&amp;gt;&amp;lt;a href="http://prestashop.com" title="some title"&amp;gt;&amp;lt;span class="icon-small helpicon"&amp;gt;&amp;lt;/span&amp;gt;English&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt; &amp;lt;li&amp;gt;&amp;lt;a href="dsjfsiodf" title="link2title"&amp;gt;&amp;lt;span class="icon-small helpicon"&amp;gt;&amp;lt;/span&amp;gt;Link 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt; &amp;lt;/ul&amp;gt; &amp;lt;/div&amp;gt; </code></pre> <p>the full error</p> <pre><code> textStatus: 'parsererror' errorThrown: 'SyntaxError: Unexpected token ' responseText: { "products": [ { "id": 1, "link": "http://localhost/presta156/index.php? id_product=1&amp;controller=product&amp;id_lang=1#/color-black/disk_space-16gb", "quantity": 4, "priceByLine": "765,04 €", "name": "iPod Nano", "price": "765,04 €", "price_float": "632.28", "idCombination": 18, "idAddressDelivery": 2, "is_gift" : 0, "hasAttributes": true, "attributes": "Black, 16GB", "hasCustomizedDatas": true, "customizedDatas":[ { "customizationId": 19, "quantity": "1", "datas": [ { "type": "1", "datas": [ { "index": 0, "value": "&amp;lt;div class=&amp;quot;ps-header-links&amp;quot;&amp;gt;&amp;lt;br/&amp;gt; &amp;lt;br/&amp;gt; &amp;lt;ul&amp;gt;&amp;lt;br/&amp;gt; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://prestashop.com&amp;quot; title=&amp;quot;some title&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;icon-small helpicon&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;English&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;br/&amp;gt; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;dsjfsiodf&amp;quot; title=&amp;quot;link2title&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;icon-small helpicon&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Link 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;br/&amp;gt; &amp;lt;/ul&amp;gt; &amp;lt;br/&amp;gt; &amp;lt;/div&amp;gt;", "truncatedValue": "&amp;lt;div..." } ] } ] } ] }], "discounts": [ ], "shippingCost": "2,42 €", "shippingCostFloat": "2.42", "wrappingCost": "0,00 €", "nbTotalProducts": "4", "total": "767,46 €", "productTotal": "765,04 €", "hasError" : false } </code></pre> <p>FUrther info: It seems the error only occurs when the html is indented. Single spaces are okay, but tabs cause the issue. Any way I can strip them off on smarty? I tried {strip}, replace ' ' : '' but they don't work!</p> <p>FIXED: I escaped tabs using |regex_replace:"/[\t]/":" "</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload