Partial Templates Location in Phalcon

phalcon, php

Solution

Partials

They have to be under the `view` folder. An example structure is below:

views/
    about/      <- AboutController
    index/      <- IndexController
    contact/    <- ContactController
    layouts/    <- Templates to override or add to the current template process
    partials/   <- (name can be anything) where you store your partials

If you want your partials to be in a specific subfolder then you will need to define it in the partial argument

$this->partial('partials/header');

The above will look for a file in the `views/partials` folder by the name of `header.phtml` or `header.volt` or whatever your registered view engine is. (phtml is the default).

NOTE You are not restricted to use a folder to add your partials in. They can happily be in the `views` folder on their own. You can organize your `views` folder the way you see fit.

The `layouts` folder under `views` contains templates that can be used anywhere in the flow of the application but are not partials. Think of them as addons to your current template flow.

A layout called `main` template would be invoked in the controller layer as such:

$this->view->setTemplateAfter('main');

If you navigate to say `/about/index`, Phalcon will pick the `views\index.volt` file, then the `layouts\main.volt` and finally the `views\about\index.volt`

NOTE Again I am using the volt example above - it could easily be phtml or any other View engine you use (phtml is the default).

HTH

Problem

Where should partial templates files be placed in Phalcon? Is there any config for that?

Original source