views:

46

answers:

1

Hello,

how do I make available some data for a layout/layout.phtml script without having to create a view script from a controller?

I've tried the following in indexAction function, but it does not work. When I do not create the view script I get an error. I could created empty one, but I don't like this solution much. Any better ideas?

$this->layout->content = "foo"
$this->_helper->viewRenderer->setNoRender(true);

Thanks in advance

A: 

You don't actually render some data you make the data available and then choose which script to render. Don't confuse the terminology.

What you have done there is stopped any script from being rendered by using the :

$this->_helper->viewRenderer->setNoRender(true);

When you do

$this->layout->content = "foo";

You are setting the property content, which you then neeed to make use in your layout script.

So then in your layout.phtml script (which I hope you have already configured to render by efault) you then just do this

 echo $this->content

Notice that I don't actually use $this->layout because when you are inside the layout, $this equal $this->layout. The same goes for $this->view->foo is $this->foo inside your view.

I hope this helps. Any questions just ask.

Laykes
Thanks for the answer, I am sorry if I explained my problem wrong. My problem is that for each controller I **have to** create the view script else I get an error. I would like to 'make available' some data from a controller for the layout.phtml. I could create empty view script and than render it to the layout, but it does not seem to be the best practice.
Petr Peller
This line: $this->_helper->viewRenderer->setNoRender(true); disables the view renderer, which should let the layout do its thing.
berty