Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:04:00+00:00 2026-05-17T03:04:00+00:00

I need a method of inserting javascript which is controller/action specific into a layout.

  • 0

I need a method of inserting javascript which is controller/action specific into a layout. That javascript needs to go inside the <head> of the document, far from where normal content is placed. I already have an infrastructure in place which allows use of multiple views per page, and the Zend_Layout I already have takes full advantage of this:

<?php
     $script = $this->layout()->script;
     if (!is_null($script)) : ?>
<script type="text/javascript"> // <![CDATA[
  <?php echo $script; ?>
// ]]>
</script>
<?php endif; ?>

However, I’d like the script output to be automatically selected, just like the normal view is automatically placed into $this->layout()->content of the layout by default. I understand this facility is provided by the ViewRenderer class. Basically, what I’d like to do is check for an instance of /VIEWPATH/scripts/CONTROLLER/ACTION.js.php, and render it as the script named output segment if it exists.

I could relatively simply create a Zend_Controller_Plugin which would automatically do that in post dispatch, but then controllers would have no way of setting values on the script’s view. I also would need some way of replicating how the ViewRenderer controller plugin is inflecting the controller and action names.

Ideally I’d just somehow tack this on to the ViewRenderer helper, but it doesn’t seem to support that kind of thing.

Am I going about this entirely wrong? Is there some mechanism for embedding page specific Javascript built into the framework? (I can’t be the only person with this problem….)

Billy3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:04:01+00:00Added an answer on May 17, 2026 at 3:04 am

    Extending my comment

    Here is the doc for what are you looking for:

    http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.headscript

    You can use captureStart() and create your scripts dynamically inside each related view.
    With this approach you don’t need to create *.js.php files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a method in JavaScript to escape all characters which are not (
I need a method that creates an empty clone of an object in a
I need a method that can monitor each change in the user in an
I need to use method like: DoSomething<(T)>(); But i don't know which Type i
I have a view that contains a javascript function that i need to init/call
I'm stuck at the moment trying to figure out a method of inserting into
basically I'm building a custom scroll bar that has a table layout inside it.
I need a tool or method that allows the transfer of data and automatically
I am in a situation where I need to step through the controller method
Is there some method that accepts inserting custom html without having to actually add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.