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 7554097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:14:42+00:00 2026-05-30T11:14:42+00:00

I have one java script definition in view(.phtml) file. This java script has dynamic

  • 0

I have one java script definition in view(.phtml) file. This java script has dynamic parameters like controller name and action name. To avoid duplicate code i want to put this code in helper file.

Now is it possible that i can use pure html and javascript code in helper file? If yes then how can i call that helper in my view file?

Or Is there any other best way to do this?

Thank you…

  • 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-30T11:14:44+00:00Added an answer on May 30, 2026 at 11:14 am

    A view helper would not be the solution in this instance. More likely you will want to use a partial (which is a view helper). A view helper is something normally used to return a piece of data to the view. A partial() or partialLoop() is used to display common html in the view (pieces of html that can be reused in multiple views).

    Here is an example of a simple view helper, notice it returns a result:

    <?php
    
    class Zend_View_Helper_FormatDate extends Zend_View_Helper_Abstract
    {
        public function FormatDate($date) {
    
            if ($date != NULL) {
                $formatedDate = new DateTime($date);
                $format = $formatedDate->format('M d, Y');
    
                return $format;
            } else {
                return '';
            }
        }
    
    }
    //This is called in the view like any other function
    <?php echo $this->FormatDate($date) ?>
    

    Now a partial will contain Html (I’m petty sure JS will work as well)

    Here is a partial that uses view helpers

    fieldset><legend>Dates and Qualifications</legend>
        <table>
            <tr>
                <td>Birth Date: </td><td><?php echo $this->escape($this->FormatDate($this->bdate)) ?></td>
            </tr>
            <tr>
                <td>Seniority Date: </td><td><?php echo $this->escape($this->FormatDate($this->sendate)) ?></td>
            </tr>
        </table>
        <table>
            <tr>
                <td>I'm a Lead:</td><td><?php echo $this->escape(ucfirst($this->ToBool($this->lead))) ?></td>
            </tr>
            <tr>
                <td>Lead Date:</td><td><?php echo $this->escape($this->FormatDate($this->ldate)) ?></td>
            </tr>
            <tr>
                <td>I'm an Inspector:</td><td><?php echo $this->escape(ucfirst($this->toBool($this->inspector))) ?></td>
            </tr>
            <tr>
                <td>Admin Login:</td><td><?php echo $this->escape(ucfirst($this->toBool($this->admin))) ?></td>
            </tr>
        </table>
    </fieldset>
    

    call this partial in your view script, the first argument is the path of the partial
    the second argument is the data used in the partial

    <?php echo $this->partial('_dates.phtml', $this->memberData) ?>
    

    the data is sent from the controller action as usual $this->view->memberData = $memberData
    This is common usage but not the only way to get data to the partial.

    in this example the partial is at the default location /application/views/scripts

    Hope this helps

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

Sidebar

Related Questions

Ok, I have one JavaScript that creates rows in a table like this: function
I have to call the web service using java script? e.g. I'm creating one
I have one string name as id in my .aspx.cs page and one JavaScript
I have a one-dimensional array of strings in JavaScript that I'd like to turn
Let's say that you have a Model that looks kind of like this: public
i have one application in that i want to know that is this in
I have to make an iframe element from java script so it isn't scrollable
I have a javascript class defined like this: myClass = { var1:0, var2:0, initVars:
I have one question. Is it possible to run unix command directly from java
First of, I'm new to ajax and Java Script.. I have spend days solving

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.