Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How do I use a particular view?

How do I tell the controller which view to use?

IndexController

indexAction()

should use Index/index.volt

and in index.volt

it should

{% extends 'layout.volt' %}
{% block body %}
my content {{ some var }}
{% endblock %}
{% block css %}
<link rel="stylesheet/less" type="text/css" href="styles.less" />
{⅜ endblock %}

or for instance in BlogController createAction() it should use Blog/new.volt



85.4k

Mvc\View tries to locate a view with the same name as the lastest action executed inside a directory with the same name as lastest controller executed.

IndexController/indexAction -> views/index/index.volt
BlogController/createAction -> views/blog/create.volt

You can "pick" another view by using the pick method on the 'view' service:

$this->view->pick("blog/new");


2.9k

Thanks but when I create a skeleton app with the devtools bash phalcon project phal simple ./ It loads views/index.volt hmm weird So I moved views/index.volt to views/index/index.volt and it worked but when I create a new file views/index.volt while index/index.volt is present it picks views/index.volt instead of views/index/index.volt I don't know if it's supposed to be like this.

Anyhow thanks for the reply.



2.9k
Accepted
answer
edited Oct '14

I just tried it again. I deleted the cache files. Deleted views/index.volt according to your information it should use views/index/index.volt

the error I get is

Warning: file_get_contents(/home/darko/NetBeansProjects/phal/app/config/../../app/views/index.volt): failed to open stream: No such file or directory in /home/darko/NetBeansProjects/phal/public/index.php on line 27
Template file /home/darko/NetBeansProjects/phal/app/config/../../app/views/index.volt could not be opened

line 27:

echo $application->handle()->getContent();

default skeleton app

Well lol Most application errors happen between the PC and the keyboard I had

{% extends 'index.volt' %}

in index/index.volt D'oh moment