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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:21:16+00:00 2026-06-15T14:21:16+00:00

Examples mylayoutfile.xml <layout> <default> <reference name=header> <block type=mynamespace_mymodule/view name=mynamespace_mymodule output=toHtml template=mymodule/html/view.phtml> <action method=setTest><param1>myparam1</param1><param2>myparam2</param2></action> </block>

  • 0

Examples

mylayoutfile.xml

 <layout>
        <default>
            <reference name="header">
                <block type="mynamespace_mymodule/view" name="mynamespace_mymodule" output="toHtml" template="mymodule/html/view.phtml">
                    <action method="setTest"><param1>myparam1</param1><param2>myparam2</param2></action>
                </block>
            </reference>
        </default>
    </layout>

app/code/local/Mynamespace/Mymodule/Block/View.php

    class Mynamespace_Mymodule_Block_View extends Mage_Core_Block_Template{
        public $test = "before any params";
            public function setTest($passedparam1,$passedparam2){
             $this->test = $passedparam1 ." ". $passedparam2;
            }

}

app/design/…/…/mymodule/html/view.phtml

<?php
echo "<pre>";
print_r($this->test);  //myparam1 myparam2
echo"</pre>";
die();

Explanation

mylayoutfile is compiled in an update through your modules config.xml

the block class prefix of mynamespace_module is also defined within your modules config.xml

mynamespace_module/view is set as the block type and instantiated and the output file of view.phtml is set

an action takes place that calls the parent node block’s method setTest passing two parameters with the value of myparam1 and myparam2.

inside of the setTest function the class parameter “test” is set to equal “myparam1 myparam2”

the template file app/design/…/…/mymodule/html/view.phtml is loaded and we echo the value of $this->test ($this refers to the earlier instantiated block class Mynamespace_mymodule_Block_View)

QUESTIONS

  1. What are some examples of use cases where this might be used?
  2. Can you pass anything other than a string? (Object,Array)?
  3. Do the automagical setters and getter methods work from inside a layout file?
  4. Can logic be used (if,then,foreach,else,etc)?
  5. Are there any scenarios where this method should not be used?
  6. Is there anything else I might be missing related to block instantiation from within a layout file?
  7. Is there anything else I might be missing related to actions from within a layout file?
  • 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-06-15T14:21:17+00:00Added an answer on June 15, 2026 at 2:21 pm
    1. Could be used for a multi-purpose template. Look at the use of setTitle in catalog.xml.
    2. Anything can be passed. Arrays can be defined in layout XML:

      <action method="setFoo">
          <arbitrary>
              <key1>val1</key1>
              <key2>val1</key2>
          </arbitrary>
      </action>
      

      Also, argument nodes can execute a helper method, the return value of which will be passed in as the value:

      <action method="setFoo">
          <arbitrary helper="foo/bar" />
      </action>
      

      This would instantiate a helper & run a method: Mage::helper('foo')->bar(). The return value could therefore be anything you want. Additionally args can be passed to the helper in child nodes!

    3. Blocks extend Varien_Object, so yes, though the setters are the only reasonable one to use.
    4. There is no direct logic for this. The closest is the action’s ifconfig attribute which will call Mage::getStoreConfigFlag() with the provided argument and process the action if the config value is true.
    5. “[c]ould not be used” – no. “Won’t matter” – yes.
    6. There are lots of nuances (too many to go into here), but you’ve got a lot already. Alan Storm gets all nuance-y in his book, No Frills Magento Layout; nothing beats exploring the limits yourself though.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Examples of the translations I need to do: $stringDate = November 2009; $output =
Examples: 1 name: Should say it has characters 10,000: OK na123me: Should say it
In examples I have seen of UINavigationContoller and UITableView , switching to next view
What examples exist of Windows Presentation Foundation (WPF) Model View ViewModel (MVVM) that include
Live Examples: Without AJAX With AJAX (click Email Us link) When I view the
The examples here show a very simplified version of a VIEW that I am
Examples first, questions second... Example 1) Non global match of '?sort=alpha&direction=asc' '?sort=alpha&direction=asc'.match(/([^?&=]+)(=([^&]*))?/); Output: //
Examples of what you can do. (defmethod some-fn ((num real)) (print an integer)) (defmethod
Examples: mapping a plural noun to its singular form: children --> child, boxes --->
VB examples please I need to return the same results from linq as I

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.