Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony's choice list as ul in a view using twig
    primarykey
    data
    text
    <p>I normally map user selectable properties to corresponding classes like so</p> <pre><code>class Person { /** * @ORM\ManyToMany(targetEntity="HobbyClass") */ private $hobby } class HobbyClass{ private $name; // e.g. "Outdoors" } </code></pre> <p>To create or edit entity I simply use entity type form field in the form. Then when I need to display the entity view with twig I just do this:</p> <pre><code> {% for item in person.hobby %} &lt;li&gt;{{ item.name }}&lt;/li&gt; {# e.g. "Outdoors" #} {% endfor %} </code></pre> <p>But this time I'm using class Selectables implementing ChoiceListInterface </p> <pre><code>class Entity { /** * @var array */ private $properties } class Selectables implements ChoiceListInterface { ... } </code></pre> <p>Then I create and edit this entity with choice type form field And of course in twig I get the keys, and not the names of the property like before</p> <pre><code> {% for item in entity.properties %} &lt;li&gt;{{ item }}&lt;/li&gt; {#e.g. "property_key", whereas its name is "Sports"#} {% endfor %} </code></pre> <p>The problem is that the data is just an array of keys that make sense only in a form. But I need to display it human readable in an entity view.</p> <p>The reason for using ChoiceListInterface is that the choice list is not going to be updated with CRUD and I can maintain it in code. It takes a little less effort to use and doesn't require a join and a db table.</p> <p>What would be the best possible solution to this:</p> <ul> <li>a. use tables and associations like before</li> <li>b. code custom twig extension which will get corresponding values from the ChoiceListInterface class</li> <li>c. use choice list and make keys translatable so they appear as property names</li> <li>d. anything else</li> </ul> <p>Thanks</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