how to implement two layer of layout in Phalcon?

80 views Asked by At

I'm using Phalcon and Volt , this is folder Structure in my project for layout

app/views/layouts/default.volt

and structure is like this enter image description here

default.volt is main layout that come with all pages .

now I need another layer of Layout to come with all pages.

this structure would be like this

enter image description here

I think it's clear with these photos .

So, How I can do that ?

2

There are 2 answers

1
Vladi On

your "main layout": app/views/[controller].volt

your "another layout": app/views/layouts/[controller].volt

your "page content": app/views/[controller]/[action].volt

0
Chess On

You can write in your views/index.volt:

{% include 'layouts/' ~ config.view.theme ~ '/header' %}
{% include 'layouts/' ~ config.view.theme ~ '/body' %}
{% include 'layouts/' ~ config.view.theme ~ '/footer' %}

So, you can manage your theme from your controller base like:

function initialize()
{
    $controller = $this->dispatcher->getControllerName();
    switch ($controller) {
        case 'controller1':
        case 'controller2':
            $this->config->view->theme = 'mytheme_with_menu';
            break;
        case 'controller3':
        case 'controller4':
            $this->config->view->theme = 'mytheme_without_menu';
            break;
    }
}