Search code examples
phpphalconvolt

Load partials based on action parameter in Phalcon


I want to load a partial view in Phalcon based on the route parameter.

I have this action, which determines the name of the partial:

public function addAction($discipline = null)
{
    if (isset($discipline)) {
        $this->view->partial = 'add' . $discipline . '.phtml';
    } else {
        $this->view->partial = 'addstatic.phtml';
    }
}

And in the main view, I want to load this partial with the Volt-command partial, like so:

{{ partial('partials/training/' ~ partial) }}

But I am facing this error:

View 'C:\xampp\htdocs\apneist_social/app/views/partials/training/addstatic.phtml' was not found in the views directory

If I browse to this file with the directory browser, I can find the file though.


Solution

  • Remove the extension (.phtml). Like:

    $this->view->partial = 'addstatic';