Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Passing object with built html code to view

Hello, I am trying to build a html table from database. I found difficilties passing some html and value as object to Volt. Maybe someone has anything to offer?


 $users = User::find();

        foreach ($users as $user) {

            $this->view->name .= '<td>'.$user. '<\td>'->name;

        }


85.2k
Accepted
answer
edited Dec '17

Im not 100% sure what you want to achieve, but maybe this example could help?

// Controller code
$this->view->users = User::find();

// Volt
<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Age</th>
        </tr>
    </thead>    
    <tbody>
        {% for user in users %}
        <tr>
            <td>{{ user.id }}</td>
            <td>{{ user.name }}</td>
            <td>{{ user.age }}</td>
        </tr>
        {% endfor %}
    </tbody> 
</table>

Nikolay, thank you very much. It is exactly what I need.