1

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:

{%for qualification in qualifications%} 
    <tr id="qualification_{{qualification.id}}">
        <td>{{qualification.name}}</td>
        <td>{{qualification.saqaId}}</td>
        <td>{{qualification.qualificationType}}</td>
        <td>{%if (qualification.course is null) %} - {%else%} {{qualification.course.name}} {%endif%}</td>
        <td>0</td>
        <td><a class="button btn-primary btn-xs" onclick="setForm({{qualification|json_encode(constant('JSON_PRETTY_PRINT'))}});">Edit</a></td>
    </tr>
{%endfor%}

I am getting the information in the table row as expected, but when looking at the HTML on the Edit button I just see onclick="setForm({});". I have tried with and without the raw, I have also tried {{qualification|json_encode(constant('JSON_PRETTY_PRINT'))}} but all return blank.

On a similar, but not related note. I have been having other issues with TWIG as well. {{dump()}} 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.

And help or advice on this would be greatly appreciated as I have run into a wall.

3
  • Did you mean json_decode? Commented Nov 30, 2013 at 19:46
  • No, json_encode is correct, as I have an object passed from my controller to twig, which needs to be encoded to JSON in order to be used by the javascript. Commented Dec 1, 2013 at 9:31
  • this could work for you or at leat give you a hint Commented Oct 21, 2017 at 21:28

1 Answer 1

0

Have you tried to {{ dump(qualifications) }}? What is the output?

Sign up to request clarification or add additional context in comments.

2 Comments

As mentioned in my original post, dump does not work. {{dump()}} and {{dump(qualifications)}} just loads for a while and then results in an unspecified server 500 error with a blank screen.
Take a look At log files, both symfony logs and php log, and post the content

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.