I am trying to display a list of courses with a checkbox allowing the user to select any number of courses from the list. I am new to Symfony and trying to follow the form approach but do not understand how to display additional attributes of an object beyond using the choice_label.
If I were just passing the course objects, I could simply use:
Template:
<form>
{% for course in courses %}
<div class="row">
<div><input type="checkbox" name="course[]" value="{{ course.id }}"></div>
<div>{{ course.name }}</div>
<div>{{ course.description }}</div>
<div>{{ course.semester }}</div>
</div>
{% endfor %}
</form>
Using the form builder, it seems my template would look like this:
{{ form_start(form) }}
<div class="row">
<div>{{ form_row(form.courses) }}</div>
</div>
{{ form_end(form) }}
How can I access these additional object attributes (name, description, etc.) within the form row? Is there a reason to use to the form builder in this case instead of the first 'by hand' approach? In summary, I need granular control of the object attributes within a given form row and the choice_label attribute alone does not seem sufficient. What is a potential solution?