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

Does Volt have parent() function like Twig?

Hi.

Layout a.volt

{% block stylesheets %}
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.2.0/united/bootstrap.min.css" rel="stylesheet">
{% endblock %}
{% block javascripts %}
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
{% endblock %}      

Layout b.volt extends a.volt

{% block stylesheets %}
    <link href="some.min.css" rel="stylesheet">
{% endblock %}
{% block javascripts %}
    <script>
        alert('Hi!');
    </script>
{% endblock %}      

In front page the result will be

HEADER
    <link href="some.min.css" rel="stylesheet">

FOOTER
    <script>
         alert('Hi!');
    </script>

But expected behavior, if parent() set somewhere, should be like this

Layout b.volt extends a.volt

{% block stylesheets %}
            {{ parent() }}
            <link href="some.min.css" rel="stylesheet">
{% endblock %}
{% block javascripts %}
            {{ parent() }}
            <script>
                alert('Hi!');
            </script>
{% endblock %}

Than in front page will next code

HEADER
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.2.0/united/bootstrap.min.css" rel="stylesheet">
    <link href="some.min.css" rel="stylesheet">

FOOTER
     <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
    <script>
        alert('Hi!');
    </script> 

twig.sensiolabs.org/doc/functions/parent.html



1.2k

It's not parent() it is super()