-- Innocentus <[email protected]> wrote
(on Saturday, 11 April 2009, 04:33 PM +0200):
> I have got a custom view-helper which could be called multiple times.
> The view-helper should create a javascript-array and render it out as
> an HeadScript.
> 
> The problem is that the view-helper is intended to return a string
> immediately after he is called from the view.
> What I want is that the view-helper doesn't return a string and
> instead of that he should save the data internally.
> Before the view will be finally rendered the view-helper should
> construct the javascript-array and render it out as HeadScript.
> 
> I don't know if a view-helper is intended for this use - maybe I
> should use an own class.
> But before I do that I need to know if there is maybe still a way.

So... why not just use the headScript() helper?

    $this->headScript()->appendScript('var foo = ' . Zend_Json::encode($array) 
. ';');

You could even wrap the above in your own helper so all you need to do
is pass the array to encode.

-- 
Matthew Weier O'Phinney
Software Architect      | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to