Questions tagged [volt]

Volt is the template engine of Phalcon PHP.

Phalcon is an open source, full stack framework for PHP 5 written as a C extension, optimized for high performance. Developers don't need to learn or use the C language, since the functionality is exposed as PHP classes ready to be used. For more information about Phalcon, you can either check the Phalcon website or the Phalcon tag.

One of the main features of Phalcon is Volt, an ultra fast template engine written solely in C.

Volt is enhancing the view layer of Phalcon with a simple and user friendly syntax. It is inspired by Twig, originally created by Armin Ronacher. which in turn is inspired in Jinja. It therefore exposes a familiar syntax to many developers, especially those that have been using Twig. Volt’s syntax and features have been enhanced with more elements and of course with the performance that developers have been accustomed to while working with Phalcon.

Volt views are compiled to pure PHP code, hence they save the effort of writing PHP code manually. As an added value, Volt is integrated with \Phalcon\Tag, making the creation of views in Phalcon applications much easier than before. For instance creating a text box is as easy as:

<label>Name</label>
{{ text_field("mytext", "size": 32) }}

which in turn when compiled becomes:

<label>Name</label>
<?php echo Phalcon\Tag::textField(array('mytext', 'size' => 32)); ?>

A core design feature in Volt is security, so it offers a limited set of functions that can be used in the templates, while aiding in escaping potentially malicious input by the users.

The first iteration of the Volt templating engine is introduced in 0.6.0, which covers a basic functional basis. As time passes by, more and more features will be added.

You can find Phalcon and Volt in the Github page of the project.

152 questions
46
votes
2 answers

How can I add volt syntax checking in PHPStorm

I want to be able to have syntax highlighting in PHPStorm for Volt, Phalcon's template engine. Is there a way to do so?
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
21
votes
4 answers

How to setup a 404 page in Phalcon

How can I set a 404 page in Phalcon to be displayed when a controller/action does not exist?
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
10
votes
1 answer

numeric loop in volt

I have read the volt documentation in phalcon page and i cant find any example for this... You can make easy loops in objects, for example, in php: foreach($pages as $page){ echo $page->title; } in volts would be ... {% for page in pages…
Stefan Luv
  • 1,179
  • 3
  • 12
  • 28
10
votes
1 answer

Easiest way to access Phalcon config values in views?

I have a section in ini files with some globally used social links, for ex: [social] fb = URL twitter = URL linkedin = URL What's the easiest way to access these, or is there a better way to organize these global variables?
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
10
votes
4 answers

what are the benefits of using a template engine

I do not understand why a developer would use Phalcon's Volt template engine. In the end, after the compilation, the same PHP files are produced, that I would have to write manually in the first place. To me, it looks only to be detrimental to the…
temuri
  • 2,767
  • 5
  • 41
  • 63
8
votes
1 answer

How can I set up a user defined function in Volt (Phalcon)

How can I set up a user defined function in Volt? For instance I want to call a function that would translate strings in my views as such: and I want the tr to map to a…
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
6
votes
9 answers

Volt directory can't be written

The error I am getting is Warning: Phalcon\Mvc\View\Engine\Volt\Compiler::compileFile(../app/views/index/index.phtml.php): failed to open stream: Permission denied in /Users/mattstephens/Sites/magpie/public/index.php on line 26 Phalcon Exception:…
Matt Stephens
  • 922
  • 1
  • 6
  • 24
5
votes
1 answer

phalcon volt bitwise operatios?

I need to run the following logic in the volt templates however it seems to be it doesnt support it. ANy ideas on workarounds ? {% for index, p_key in partner_var %}
mahen3d
  • 7,047
  • 13
  • 51
  • 103
5
votes
2 answers

Phalcon Volt check_field with if else statement for checked

I have a checkbox im trying to build in Volt: So now i would normally write it like this {{ check_field( 'class':'my class', 'data-size':'small',…
user1547410
  • 863
  • 7
  • 27
  • 58
5
votes
3 answers

Netbeans syntax highlighting for volt (twig) and php in phtml files

I'm working with Phalcon in Netbeans. I see I can use twig plugin for template highlighting for volt files. I am using phtml files and want highlighting for volt (twig) and php. Is this possible? Also related - Netbeans keeps duplicating my phtml…
Ally
  • 955
  • 1
  • 15
  • 33
4
votes
2 answers

Get size of an array in Volt

In Volt (the template engine for Phalcon) how can I get the number of elements in an array? I've tried sizeof and also count, length and size (hoping to stumble upon the correct command). In this particular instance I'm just interested in whether…
Kvothe
  • 1,819
  • 2
  • 23
  • 37
4
votes
2 answers

phalcon : volt get value from array which key taken from variable

In phalcon templating engine volt (which is similar to twig) you can fetch all records by : {% for product in products %} Name: {{ product.name }} Description: {{ product.description }} price: {{ product.price}} {% endfor %} So, in my…
AzDesign
  • 1,169
  • 1
  • 8
  • 18
4
votes
1 answer

What is the difference between *.volt and *.phtml files in PhalconPHP?

Iin the sample projects of Phalcon, in the views directory we have some files with volt suffix and phtml suffix. What is the difference between this two suffix? When we must use Volt and when we must use phtml ?! please explain for me...
Omid Ebrahimi
  • 1,150
  • 2
  • 20
  • 38
3
votes
1 answer

phalcon volt template engine remove php code blocks

How can i remove php code blocks from volt template file, which has .phtml extension? forexample:

{{tutorial}}