简体   繁体   中英

Change default template to 'common.volt'?

From what I understand, Phalcon uses index.phtml or index.volt in app/views as the base template for any page that doesn't have a template specified.

How can I change this to use app/views/layouts/common.volt ?

It uses index.volt or index.html if the latest executed action is 'index' (indexAction in the controller).

You can use a common layout by setting a 'template before' or a 'template after':

https://github.com/phalcon/invo/blob/master/app/controllers/ContactController.php#L7

Update August 2016 : since the above information is no longer available in the given link, adding it here:

public function initialize()
{
    $this->view->setTemplateBefore('your-template-name');
    $this->view->setTemplateAfter('your-template-name');
}

More info here: https://docs.phalconphp.com/en/latest/reference/views.html#using-templates

When setting up the view component we need to declare $view Object like the following:

$di->set('view', function () use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);
    $view->setLayout('common');
......

using setLayout(String name) method to set default layout for app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM