We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Changing function in Volt

Hi,

is it somehow possible to change how {% extends "index.volt" %} in Volt works? or just update the parameter before rendering? Let's say i want to use something like namespace with assign dir, for example:

{% extends "Default\index.volt" %}

and before render replace Default\ with ../default/ and rthen render?



2.1k

i dont think volt can do that.

but i believe you can do

define(DEFAULT_PATH,"somewhere");
{% extends DEFAULT_PATH."\index.volt" %}
edited Jan '15

Well after googling little bit, i found thatican use vol extension.

I have created simple class

class VoltExtension { public function compileStatement($statement) { if($statement['type'] == 310) { $statement['path'] = 'index.volt'; } return $statement; } }

but it is not able to change path, whtever i enter it will do nothing...is there some idea how to update statement?

I'm really not sure what advantage you get by using namespaces rather than directory names. To me, it seems like a lot of work for pretty much no gain.

It's like saying that you see no advantage in using namespaces for classes when you can use long class names...i'm trying to remake my old project with quite a big template structure to somethin more reusable, and i big benefit in that....

Namespaces let you duplicate class names, so there is a clear advantage. Namespaces work sort of like directories though, so switching from ../default/index.volt to Default/index.volt really only saves you 2 characters.

Of course you're free to do what you want, I was just giving my opinion that the ends didn't appear to justify the means.