Volt - why use it and what are the benefits?

Hi all,

I get how Volt works, but I do not understand why a developer would use it. Because in the end, after the compilation the same PHP files are produced, that I can write in the first place.

Is the answer "so you could pass .volt files to a front-end guy"?

Any other benefits?

Thanks, Temuri



so you said:

Examples I can give you are template inheritance

However, so far, I have not seen anything that I can do with Volt templates that cannot be done inside phtml files.

I am very much intrigues by Volt engine, but struggling to find a missing piece.

Is there a doc page/section that lists Volt-specific functions that give me advantage over working with phtml?

I'd like to add that I am absolutely stunned by the work you've done. It's just incredible.

Regards, Temuri


Thank you for your kind words.

The reference in the manual is here http://docs.phalcon.io/en/latest/reference/volt.html

True most of the things you can do with Volt you can do it yourself with phtml files. However there are some that you cannot. For instance template inheritance (as I wrote), an easy way to render partials and also macros. The document section above lists all that.

Again it is ease of you and entirely up to the developer to use whatever they like. However for me personally:


{% for row in data.projects.project %}
<div class="proj-item">
    <h4><a href="/project/view/{{row.prj_id }}">{{ row.prj_name }}</a></h4>
    <p>{{ row.prj_desc }}</p>
{% endfor %}

is easier to write and code than this:

<?php foreach ($data->projects->project as $row) { ?>
<div class="proj-item">
    <h4><a href="/project/view/<?php echo $row->prj_id; ?>"><?php echo $row->prj_name; ?></a></h4>
    <p><?php echo $row->prj_desc; ?></p>
<?php } ?>