Getting current page - Magento - php

The thing is that I have logo displayed on only homepage in Magento checking if it's homepage with getIsHomepage();. Now the thing I want to do is to display logo inside header only on Dashboard page, do you know any alternative to getIsHomepage but to check if it's My account page?
Thanks

It's best practice to use xml to do this instead of parsing url. Add this to your local.xml:
<customer_account_index>
<reference name="header">
<action method="setTemplate"><template>page/html/customer_account_header.phtml</template></action>
</reference>
</customer_account_index>
And copy and edit your header.phtml file to template/page/html/customer_account_header.phtml

If you want to out logic for customer account page then
First fetch current routers and controllers and action to headere.phtml
logic is like
for magento customer dasboard page url is customer/account/index
then
<?php $action = Mage::app()->getFrontController()->getAction();
echo $action->getFullActionName('_');
if($action->getFullActionName('_')=="customer_account_index")
{
}
?>

Related

Customer Registration Form Template Not Working On Site Home Page

I am trying to call Magento customer registration form on my home page. When I call it on the home page I try both ways, static block or template.phtml file and my site stops working. Can anyone suggest a solution to me?
<?php
echo $this->getLayout()->createBlock('cms/block')->setBlockId('register-form')->toHtml();
<?php
echo $this->getLayout()->createBlock('core/template')->setTemplate('persistent/customer/form/mini.register')->toHtml();
when using a template file, add the '.phtml' extension to the name of the file.
in your example:
echo $this->getLayout()->createBlock('core/template')->setTemplate('persistent/customer/form/mini.register.phtml')->toHtml();
please not that the code above will only work in template files.
if you are trying to add this to your homepage through the admin cms page, then you would do this:
{{ block type="core/template" template="persistent/customer/form/mini.register.phtml" }}
or through a layout file:
<block type="core/template" template="persistent/customer/form/mini.register.phtml" />

How to call the Search bar from homepage to all other pages in Magento 1.9?

My Search bar is currently on my homepage(http://www.ashvinrx.com/magento/index.php/).
block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
I want to make the search bar appear on my 'newproducts' page (http://www.ashvinrx.com/magento/index.php/newproducts).Please help.
It looks like this is cms page.
you can add this code in that page {{block type="core/template" name="top.search" template="catalogsearch/form.mini.phtml"}}
and search bar will appear on that page. and if you want to display this in any specific place let me know i will guide you with this.
You can try this code also in phtml file.
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalogsearch/form.mini.phtml')->tohtml(); ?>
For Magento recent versions try this format below:
<?php echo $this>getLayout()createBlock('Magento\Framework\View\Element\Template')->setTemplate('Magento_Search::form.mini.phtml')->toHtml() ?>

Magento, hide the toolbar only in a specific block

I'm trying to hide the toolbar of the products only in the block footer but without success. I have tried using the function
<?php if(Mage::app()->getLayout()->getBlockName () != "footer"): ?>
but it returned an error. I do not want me to hide the toolbar across the page, but only in a specific block.
How can I hide the toolbar in a specific block?
Thanks for any help.
You can remove block using chenging layout xml,add like as below in your local.xml file
<reference name="footer">
<remove name="block name" />
</reference>
This URL have more details about local.xml
http://magebase.com/magento-tutorials/5-useful-tricks-for-your-magento-local-xml/
Although I would suggest doing most of those kind of task in the layout, as Shijin is proposing it. If you tried it that way and for some reason cannot do it properly in the layout, you can use the method getNameInLayout available for any block extending Mage_Core_Block_Abstract
<?php if($this->getNameInLayout() != "footer"): ?>

magento - use a frontend template in adminhtml

I have a order timeline page on frontend at :
/magento/app/design/frontend/default/mytheme/template/sales/order/info.phtml
I am trying to use the same page on adminhtml, from sales -> orders on a single view order page I am creating a hyperlink on click of that I would like to show a popup that will display the timeline same as displayed on frontend page of info.phtml. Can I use the same template info.phtml I have in frontend or I have to create one more for backend? also any ideas how to approach this? thanks
I have created a black in
magento/app/design/adminhtml/default/default/layout/sales.xml and added the template code of info.phtml in timeline.phtml
<adminhtml_sales_order_timeline>
<block type="adminhtml/sales_order_timeline" name="timeline_tracking" template="sales/order/view/timeline.phtml"></block>
</adminhtml_sales_order_timeline>
Edit :
The request is going to the controller :
public function timelineAction()
{
$this->loadLayout();
$this->renderLayout();
}
which loads the following layout :
<adminhtml_sales_order_timeline>
<remove name="header" />
<remove name="footer" />
<block type="adminhtml/sales_order_timeline" name="sales_order_timeline" template="sales/order/timeline/timeline.phtml" />
</adminhtml_sales_order_timeline>
this removes the header and footer but this is not displaying the content of the template timeline.phtml, I have not done any other configurations for block, what am I missing?
your Admin layouts will look for the phtmls inside adminhtml/ folder and not the frontend/ folders. What you can do is copy the info.phtml inside your adminhtml/default/default/template/your_folder_name and include that in your adminhtml layout.

Magento Contact form in phtml file of custom created widget

I'm developing a widget for Magento, in this widget i need to load the magento contact form. I've tried several options, but none of them seem to work.
the widget is located in
app/
code/
local/
CompanyName/
WidgetName/
and the phtml files are located in
app/
design/
frontend/
default/
default/
template/
templatename/
templatefile1.pthml
templatefile2.pthml
templatefile3.phtml
to load the magento contact form i've added this in templatefile3.phtml
<?php echo $this->getChildHtml('contactForm') ?>
but it's not showing up, even after adding xml to 2 files, i've added this line into app/design/frontend/base/default/layout/catalog.xml, right below <reference name="content">
<block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"/>
and also added this code to app/design/frontend/base/default/layout/default.xml (this file didn't even exist)
<default>
<cms_page>
<reference name="content">
<block type="core/template" name="contactForm" as="contactForm" template="contacts/form.phtml">
<action method='setBlockId'><block_id>contactForm</block_id></action>
</block>
</reference>
</cms_page>
I have the idea i'm not putting the xml in the right files, but i have no idea witch files to use otherwise, and can't find any other tips than these two on the internet.
Can someone help me out?
You can add the contact form to any CMS page using CMS tags like this inside the CMS content box:
{{block type="core/template" name="contactForm" template="contacts/form.phtml"}}
You could create a new page, and then inssert that snippet to show the contact form on this new page.
you could also make a copy of form.phtml and modify it for your needs, and update the tag code to use the new template.
Please use the following function to display inside templates.
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Contact::form.phtml")->toHtml(); ?>
You can't just create a default.xml - to let Magento know that that a layout xml file exists you'd have to go through and create a module and specify the layout file's location. that is a very long winded way round of trying to achieve what you need.
Also I believe the handle <cms_page> is not supported. Referencing a block in a CMS page is best done by placing your xml in the layout update section under the 'design' tab for that CMS page.
So it's fairly straight forward to put the contact form into a CMS page - again use the layout update facility. Simply enter the following xml...
<reference name="content">
<block type="core/template" name="contactForm" template="contacts/form.phtml"/>
</reference>
Note you don't need a layout handle - Magento already knows of course the specific CMS page you are inserting content into because this is a layout update for that page. So in the above you are just referencing the structural block you want to add to (in this case content) and telling Magento to add the contactForm block along with its associated template location.
I've worked on a site using this method before. you will likely find that once you have called the contactform into your CMS page, and despite appearing successfully in a browser, the form doesn't actually post. In fact the form will only send if used from the intended page yoursite.com/contacts
Simple fix. Create the file app/design/frontend/YOUR-PACKAGE/YOUR-THEME/template/contacts/form.phtml and duplicate the required content from the default form.phtml into it.
Change the script at the bottom of the form.phtml file from:
<script type="text/javascript">
var contactForm = new VarienForm('contactForm', true);
</script>
To:
<script type="text/javascript">
elem = $("contactForm");
elem.writeAttribute('action', '/contacts/index/post');
</script>
And your CMS page contact form will now post as required.
Just as an addition (you may or may not find this useful).
I had a need for the contact form on my CMS page to be different from the standard form which appears on contacts. This is really simple too using the method above.
Duplicate the file app/design/frontend/YOUR-PACKAGE/YOUR-THEME/template/contacts/form.phtml and rename as something like app/design/frontend/YOUR-PACKAGE/YOUR-THEME/template/contacts/customForm.phtml - then make your required amends like different fields etc...
now in the layout update for the CMS page you want it to appear in simply add the following xml:
<reference name="content">
<block type="core/template" name="customContactForm" template="contacts/customForm.phtml"/>
</reference>
And that's it.
Note how the block name has changed - the block name can literally be anything - Magento doesn't care what you call it but I would obviously recommend something logical!

Categories