Note that there are some explanatory texts on larger screens.

plurals
  1. POPass TWIG Objects to Javascript (json_encode result is empty)
    primarykey
    data
    text
    <p>I have a collection of items passed from my controller to my twig template called qualifications. I then loop through each object in the collection and print it to a row in the table. Every respective row has an "Edit" button, which should pass that object's values to a javascript function. Here is my code:</p> <pre><code>{%for qualification in qualifications%} &lt;tr id="qualification_{{qualification.id}}"&gt; &lt;td&gt;{{qualification.name}}&lt;/td&gt; &lt;td&gt;{{qualification.saqaId}}&lt;/td&gt; &lt;td&gt;{{qualification.qualificationType}}&lt;/td&gt; &lt;td&gt;{%if (qualification.course is null) %} - {%else%} {{qualification.course.name}} {%endif%}&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;&lt;a class="button btn-primary btn-xs" onclick="setForm({{qualification|json_encode(constant('JSON_PRETTY_PRINT'))}});"&gt;Edit&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; {%endfor%} </code></pre> <p>I am getting the information in the table row as expected, but when looking at the HTML on the Edit button I just see <code>onclick="setForm({});"</code>. I have tried with and without the raw, I have also tried <code>{{qualification|json_encode(constant('JSON_PRETTY_PRINT'))}}</code> but all return blank.</p> <p>On a similar, but not related note. I have been having other issues with TWIG as well. <code>{{dump()}}</code> just loads a while and then gives a blank page with an unspecified 500 error. have tried activating the twig debug in services.xml and config.yml with what documentation I could find, but to no avail. This, however is not my primary concern, my primary concern is json_encode returning an empty result.</p> <p>And help or advice on this would be greatly appreciated as I have run into a wall.</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.
 

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