0

is it possible to make it happen? My view helper works fine if in a view that was a result of a controll. But I would like to have some dinamic layout, for example, to render a jquery menu according to the state I'm in.

If I call the helper from layout headScript never happens to echo the appendScript command I did inside the helper.

thanks!

1

2 Answers 2

1

You have a couple of options here.
the easiest way to do what you want would be to use the inlineScript() view helper and add it to the view in the bootstrap or directly in the layout script. The inlneScript() helper works the same way as the headScript() helper but puts the code in the markup. I sometimes use the inlineScript() helper to pass configuration data to audio and video players.

Alternatively you can build your own placeholder using your view helper and just initialize it in the bootstrap.

here is a simple example of a custom placeholder that renders menus:

The Bootstrap:

 protected function _initMenus() {
        //get view object
        $view = $this->getResource('view');
        //assign the id for the menus...
        $view->mainMenuId = 4;
        $view->adminMenuId = 5;
    }

The layout:

<?php
$this->layout()->adminMenu = $this->action(
        'render', 'menu', null, array('menu' => $this->adminMenuId))
?>
<div id="adminMenu">
     <!-- Render the placeholder -->
     <?php echo $this->layout()->adminMenu ?>&nbsp;
</div>

This placeholder just uses the action() helper to call a renderAction(), but what you can do with placeholders is pretty much limited by your imagination.

Sign up to request clarification or add additional context in comments.

2 Comments

I did a little mistake forgeting that I should call the action before the headScript/headLink. After that worked like a charm! many thanks! ps. Just noticed that you dont need the bootstrap part.
The bootstrap part is just to set the defaults, in this case.
0

I don't think this is possible since if the helper is called in the layout, it will probably be calling headScript after the headScript helper has run. The only way to get it to work would be to ensure your helper is called near the top of the layout, before the headScript call.

6 Comments

yes, but the layout()->content do exactly this when renders a view. :/
The view is rendered before the layout, layout()->content simply outputs it. So that's why helper calls will always work in the view.
So, I could render it myself and pass to the layout through the view. A plugin could be that place?
Your best bet is to simply output the <script> tag in the helper. Although it would be nice to use the headScript helper, script tags don't have to be in the <head> section.
Yes but in a modular fashion I need to do the same with the css.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.