We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Does Volt have something like request.ajax extends like Twig?

{% extends request.ajax ? "base_ajax.html" : "base.html" %}

Thank's for help...

I think you could do something like:

{% if request.isAjax() %}
    {% extends "base_ajax.html" %}
{% else %}
    {% extends "base.html" %}
{% endif %}

Request API: https://docs.phalcon.io/en/latest/api/Phalcon_Http_Request.html

edited Oct '14

Sorry for late, I was trying to make it in another way, maybe creating a custom function inside volt, but nothing work, so I test this way as last resource, and it fails...

**Fatal error**: Uncaught exception 'Phalcon\Mvc\View\Exception' with message 'Extends statement must be placed at the first line in the template in ..... on line 2' in ....:10 Stack trace: #0 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->_compileSource('{% if request.i...', false) #1 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compileFile('/...', '...', false) #2 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compile('...') #3 [internal function]: Phalcon\Mvc\View\Engine\Volt->render('...', NULL, true) #4 [internal function]: Phalcon\Mvc\View->_engineRender(Array, '...', true, true, NULL) #5 ...(10): Phalcon\Mvc\View->render('auth', 'signup') #6 /... in /... on line 10

Closer solution is using partials, is gonna change your logic for rendering views but is the only way to make it...

{{ request.isAjax()?partial("base/base-ajax") :partial("base/base-default") }}

Thank's for help!


Why don't you use template layout and take care of that in the controller or something instead of view.