Check out the CourseFREE Udemy course when you sign up this month
The examples on this site are currently tested to work on Phalcon V3.4 and Phalcon Devtools V3.2 Some issues may arise when using later versions.

Please get in touch or post a comment below the post if you encounter a problem.

The Phalcon template inheritance model allows us to place blocks of HTML or code in certain templates which will then be inherited by many other views in accordance with the inheritance model.

In this example we will place a HTML block containing a Navigation bar in the template on the top of inheritance tree - index.phtml or index.volt. This navigation bar will then be inherited and appear on all pages of the website.

Creating links with volt is much neater and more straightforward than the phtml equivalent. The following block contains Volt code and as such the file need to be saved as a .volt file in order to function correctly.

Take the following block of code and place it in /app/views/index.volt

<nav class="navbar navbar-inverse">
    <ul class="nav navbar-nav">
        <li class="active"><a href="{{ url('member/search')}}">Home</a></li>
        <li><a href="{{ url('member/new')}}">New Member</a></li>
        <li><a href="{{ url('booking/search')}}">Bookings</a></li>
        <li><a href="{{ url('court/search')}}">Courts</a></li>

Place the file in the following location within the file

Save this file as /app/views/index.volt

By way of comparison here is the phtml equivalent.

<nav class="navbar navbar-inverse">
    <ul class="nav navbar-nav">
        <li><a href="<?php echo $this->url->getBaseUri()?>/member/search">New Member</a></li>
        <li><a href="<?php echo $this->url->getBaseUri()?>/booking/search">Bookings</a></li>
        <li><a href="<?php echo $this->url->getBaseUri()?>/court/search">Courts</a></li>

Another alternative way to generate links in phtml is as follows

<?php echo $this->tag->linkTo(["Member/search"]); ?>

Clearly the volt syntax is neater and more elegant than either of the phtml approaches. The good news is that both approaches can be used in harmony. Where the index.volt and index.phtml are both included the index.volt file will take precedence.

This approach quickly and neatly places a navigation bar on all pages of the website as follows.