Passing a Helper Class a Parameter Through a Layout XML File - magento

I have a working link being added to the top.links block like this:
<block type="page/template_links" name="top.links" as="topLinks">
<action method="addLink">
<label>About Us</label>
<url helper="mymodule/getAboutUsUrl"/>
<title>About Us</title>
<prepare/>
<urlParams/>
<position>20</position>
</action>
</block>
Eventually I wanted getAboutUsUrl to turn into getExternalSiteUrl. I want that one function to take parameters. For instance, getExternalSiteUrl('about-us') which would then return something like /the/url/about-us. However, I can't seem to find a way to send a helper class parameters in a Layout XML file. I searched for other modules doing this already, and couldn't find one in the Customer module where I searched.
Can anyone help?

<block type="page/template_links" name="top.links" as="topLinks">
<action method="addLink">
<label>About Us</label>
<url helper="mymodule/getAboutUsUrl">
<arg>Now with more args!</arg>
<!-- will result in the string being passed as first arg -->
</url>
<title>About Us</title>
<prepare/>
<urlParams/>
<position>20</position>
</action>
</block>
Note that helpers do not extend Varien_Object, therefore your method will need to explicitly define the getAboutUsUrl() method.

Related

Magento getChildHtml block not rendering

I'm attempting to rearrange some elements on a webpage and my code won't render it its new position.
The top of the page is handled in view.phtml and the bottom in list.phtml. I'm wanting to move form.phtml from view to list.
The xml looks like this:
<block type="review/product_view" name="product.info" template="catalog/product/view.phtml">
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml">
<action method="disableGallery"/>
</block>
<block type="review/form" name="product.review.form" as="review_form" template="review/form.phtml"/>
the view.phtml contains this call:
<?php echo $this->getChildHtml('review_form') ?>
However, no dice. I'm very new to Magento, so any help would be great. I've looked into the following questions and more with no results:
Nested block within a reference not rendering when using ->getChildHtml()
Magento $this->getChildHtml('media') return blank
Call magento template via $this->getChildHtml()
Thanks!
As per as your description,review child block is call in under view then...
it should be
<block type="review/product_view" name="product.info" template="catalog/product/view.phtml">
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml">
<action method="disableGallery"/>
</block>
<block type="review/form" name="product.review.form" as="review_form">
<block type="page/html_wrapper" name="product.review.form.fields.before" as="form_fields_before" translate="label">
<label>Review Form Fields Before</label>
<action method="setMayBeInvisible"><value>1</value></action>
</block>
</block>
.........

getChild method in a module doesn't seem to refer to a child(?)

I am using the Meanbee Infinite Scroll module in my project. I have it working for normal category product listings. But now I'm attempting to have it activate on my custom made module.
However I am stumped over line 68 in Script.php:
66 return (
67 $block !== false &&
68 $block->getChild('toolbar') !== false && // <-- This line
69 $this->_getPagerBlock() !== false &&
70 $this->_getPagerBlock()->getCollection()
71 );
There is no xml element that has attribute name of toolbar. Even in the normal category xml that is working. So what is "toolbar" refering to?
A var_dump($block->getChild('toolbar')); returns false on my page but not on the normal category product listing page.
My XML is as follows (for clarity):
<block type="mynamespace/mymodule" name="mymodule.view" template="mynamespace/mymodule/view.phtml">
<block type="catalog/product_list" name="product_list" template="toxicfox/giftfinder/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</block>
And the core XML (which works with the Infinite Scroll module) is:
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</block>
As you can see, neither block of XML has any element with an attribute name of "toolbar". The only difference is line 1.
Any help is appreciated.
In the Mage_Catalog_Block_Product_List::_beforeToHtml() method, the toolbar block is retrieved from the layout with the name that was indicated by the setToolbarBlockName action, then set as a child block of the products list with the toolbar alias.
In your case, the problem may be that the $block hasn't been output yet with toHtml(), so that it doesn't know yet about its toolbar child, or something of this kind (hard to say because the extension is commercial).

How to add css to login,register and logout link separately?

I am trying to have different css for login register and login links. But as they are being added using template_links block and they are automatically rendered and no template file for specific one, I am unable to achieve this.
<block type="page/template_links" name="account.links" as="accountLinks"/>
At the moment I tried changing the css but obviously css rules are getting assigned to all of it at the same time.
How can I achieve this please suggest something. Thank you
can I do that using layout?
<customer_logged_in>
<reference name="account.links">
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>2</position></action>
<action method="removeLinkByUrl"><url helper="customer/getRegisterUrl" /></action>
</reference>
</customer_logged_in>
<!--
Load this update on every page when customer is logged out
-->
<customer_logged_out>
<reference name="account.links">
<action method="addLink" translate="label title" module="customer"><label>Login</label><url helper="customer/getLoginUrl"/><title>Login</title><prepare/><urlParams/><position>1</position></action>
<action method="removeLinkByUrl" ifconfig="enterprise_invitation/general/registration_required_invitation"><url helper="customer/getRegisterUrl" /></action>
<!-- <action method="addLink" translate="label title" module="customer"><label>register</label><url helper="customer/getRegisterUrl" /><title>register</title><prepare/><urlParams/><position>100</position><li/><a/><before_text> or </before_text><after_text>.</after_text></action> -->
</reference>
<remove name="wishlist_sidebar"></remove>
<remove name="reorder"></remove>
<remove name="top.menu" />
</customer_logged_out>
<!--
Layout for customer login page
-->
<customer_account_login translate="label">
<label>Customer Account Login Form</label>
<!-- Mage_Customer -->
<remove name="right"/>
<remove name="left"/>
<reference name="head">
<action method="addJs"><script>jquery/jquery.js</script></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
</reference>
</customer_account_login>
current theme links look like this
------EDIT-----
After placing class in aparam It is still applying same old css rules as in the html showing no class element. I have place the .logout-link class in the same theme in custom and style.css but still no luck. It is not finding this class and not even it is showing in chrome developer tools.
<customer_logged_in>
<reference name="account.links">
<action method="addLink" translate="label title" module="customer">
<label>Log Out</label>
<url helper="customer/getLogoutUrl"/>
<title>Log Out</title>
<prepare/>
<urlParams/>
<position>2</position>
<aParams>class="logout-link"</aParams>
</action>
<action method="removeLinkByUrl"><url helper="customer/getRegisterUrl" /></action>
</reference>
<div class="header-links-wrapper">
<ul class="links">
<li class="first last">Log Out</li>
</ul>
</div>
You can apply a class with the addLink method using the following:
<liParams/>
<aParams>class="My Class Name"</aParams>
<beforeText/>
<afterText/>
So for example, to add a class to your logout link, you can do this:
<action method="addLink" translate="label title" module="customer">
<label>Log Out</label>
<url helper="customer/getLogoutUrl"/>
<title>Log Out</title><prepare/>
<urlParams/>
<position>2</position>
<liParams/>
<aParams>class="logout-link"</aParams>
<beforeText/>
<afterText/>
</action>
Then you just add a css definition for logout-link

Magento: Add Block Before Footer

I'm using GrayScale template, and I want to move the recent viewed to a block before the footer.
I need this block with a different color from footer.
So, I removed this block of page.xml:
<block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
And added to footer block of page.xml:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
<block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
<block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
<label>Page Footer</label>
<action method="setElementClass"><value>bottom-container</value></action>
</block>
<block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
</block>
Perfect!
But, I need this block before footer and not inside...
How can I do this???
Thanks!
Open your Page.xml file and find the following block
<block type="page/html_footer" name="footer" as="footer" template="page/htmlfooter.phtml">
It should be arond line number 100.
Inside the block paste the following code
<block type="reports/product_viewed" name="reports.product.viewed" as="recently_viewed" template="reports/product_viewed.phtml">
<action method="setColumnCount"><columns>4</columns></action>
<action method="setItemLimit"><type>recently_viewed</type><limit>4</limit></action>
</block>
The block should look like this
Now open your footer.phtml file and before the footer, i.e.
<div class="footer-container">
write the following code
<?php echo $this->getChildHtml('recently_viewed') ?>
And change the child block calling like the following
Now any logged in user will be able to view their recently viewed product and yes, it is outside the footer.
You can style it according to your needs, and you can also set the column count from the block itself.
Enjoy.
Try adding this right above the 'footer' section:
<block type="core/text_list" name="review.before.footer" as="review.before.footer" translate="label">
<block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
</block>

magento Baseurl from helper function

I want to get custom URL from magento helper in this way:
<action
method="addLink"
translate="label title"
module="customer">
<label>About Us</label>
<url
helper="customer/getAboutUsUrl">
about
</url>
<title>About Us</title>
<prepare/>
<urlParams/>
<position>1</position>
</action>
So what I did is define a function getAboutUsUrl() under local directory within Customer Helper Directory. But it does not return the base url as I expected.
What do I have to do to get the baseurl with about us link?
Thanks
You should use cms/page/getPageUrl helper method and pass CMS-page identifier as its parameter like in the following example:
<action
method="addLink"
translate="label title"
module="customer">
<label>About Us</label>
<url helper="cms/page/getPageUrl"><pageId>about</pageId></url>
<title>About Us</title>
<prepare/>
<position>1</position>
</action>

Resources