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

Volt extends from virable

Hello.

I am trying to use the extends function in volt, but with a virable the referes to the file. But it wont allow me to do so:

{% extends virable %}

I also tried to do:

{% extends "template.volt" %}

{% include("page.volt") %}

Is there any workaround with this?

Hmm, I remember doing something similar way back - but you have to take into account that Volt engine is compiled first - then your PHP logic AFAIK. I remember it was fairly difficult to achieve what we needed for the project - but I managed at the end. The thing is you have to prepare it to "listen" for the variable value at runtime as the variable is N/A at compile time.

I'll try to find that example which would shine some light on this more than just my words.

That would be great thank you!



79.0k
Accepted
answer
edited Feb '19

Well, it turned out it's not what you need.

I have tried to modify it a bit and use it with extends or include Volt syntax, but no luck. It just won't accept it - it breaks. It seems that part is fixed and unchangable at user level.

I have stumbled upon this thread though: https://stackoverflow.com/questions/38138018/phalcon-extends-volt-with-variable-any-other-way-to-make-that-work

Try to ping @nikolay-mihaylov (https://forum.phalcon.io/user/4153/nikolay-mihaylov) as examples he provided at SO do not work.

IMHO your best route is using partials for this. e.g. https://forum.phalcon.io/discussion/2200/does-volt-have-something-like-request-ajax-extends-like-twig-#C7697

Last but not least - this is also something interesting to make a proof of concept: https://docs.phalcon.io/3.4/en/volt#extending-extensions

With extensions the developer has more flexibility to extend the template engine, and override the compilation of a specific instruction, change the behavior of an expression or operator, add functions/filters, and more.

Whenever it is possible to override this specific keywords - is something to be verified.

Thank you for spending your time trying to find a solution for my problem.

I will look into the links you sendt me, and maybe find an other way to solve my problem, in this case without volt extends.