Dynamic templates and controllers

Now that we have a few records in our table, let's see how to fetch them via controller and feed their properties to our templates. What we expect from our dynamic template is to receive an object and show its properties. In our case, the object is User and its properties are name, bio, and email. So, edit the about/index.html.twig template as follows:

{# mava/app/Resources/views/about/index.html.twig #}

{% if user %}
  <h1>User Profile</h1>
  <strong>Name: </strong>{{user.name}} <br/>
  <strong>email: </strong>{{user.email}} <br/>
  <strong>Bio: </strong>{{user.bio}} <br/>
{% else %}
  mava is a web app for task management and team collaboration. <br/>
{% endif %}

Next, add a few lines to aboutAction() to retrieve information ...

Get Mastering Symfony now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.