I am new to magento, so please forgive me if I have asked anything wrong. I have created a custom module for instagram Login, I just want to call a particular block from that instagram module to another layout file. I have called that block printed in my view page using
<?php echo $this->getChildHtml('media_new'); ?>
My block got called but functionalities are working and form is not submitting.
My custom module layout file. Instagram.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<instagram_index_instagram_signup>
<reference name="head">
<action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action>
</reference>
<reference name="content">
<block type="core/template" name="instagram.signup" template="instagramlogin/Instagram_signup.phtml"></block>
</reference>
</instagram_index_instagram_signup>
</layout>
I want to call the above block to another module layout file:
My another module layout page:
<marketplace_vendor_login>
<reference name="head">
<action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action>
</reference>
<remove name="right"/>
<remove name="left"/>
<reference name="before_body_end">
<block type="facebookfree/init" name="belvg_facebookfree_block">
<action method="setTemplate" ifconfig="facebookfree/settings/enabled" ifvalue="1">
<template>belvg/facebookfree/block.phtml</template>
</action>
</block>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="marketplace/vendor_login" name="customer_form_login" template="nbmpmarketplace/login.phtml" >
<block type="facebookfree/links_button" name="belvg_facebookfree_button" template="belvg/facebookfree/form/button.phtml" />
<block type="core/template" name="instagram.signup" as="media_new" template="instagramlogin/Instagram_signup.phtml"></block>
</block>
</reference>
</marketplace_vendor_login>
Here I have called my custom block, then printed in my view page as:
<?php echo $this->getChildHtml('media_new'); ?>
My controller code for instagram:
class Blazedream_Instagram_IndexController extends Mage_Core_Controller_Front_Action
{
public function instagram_signupAction()
{
if ($this->getRequest()->isPost()){
if($this->getRequest()->getPost('instagram-email')){
$instagram_email = $this->getRequest()->getPost('instagram-email');
$customer_model = Mage::getModel('instagram/instagram');
$site_customer = $customer_model->checkCustomer($instagram_email);
if($site_customer){
$instagram_customer = Mage::getModel('instagram/instagram')->getCollection()
->addFieldToFilter('customer_id', array('eq' => $site_customer));
if(count($instagram_customer)==1){
Mage::getSingleton('core/session')->setInstagramEmail($instagram_email);
$this->_redirect('instagram/index');
}else{
Mage::getSingleton('customer/session')->addError('Email Id Already Registered.');
$this->_redirect('sellerlogin');
}
}else{
Mage::getSingleton('core/session')->setInstagramEmail($instagram_email);
$this->_redirect('instagram/index');
}
}
}
$this->loadLayout();
$this->getLayout()->getBlock('instagram.signup');
$this->renderLayout();
}
}
It is not coming into this controller function, That i have used for instagram module.
My view page: instagramlogin.phtml
<div style="display: none">
<style type="text/css">
#cboxContent.newsletterbox {
<?php if($backgroundImage){?> background-image: url(<?php echo Mage::getBaseUrl('media').'/wysiwyg/magenthemes/newsletter/'.$backgroundImage;?>);
<?php }?> background-position: left top;
background-repeat: no-repeat;
background-color: <?php echo $backgroundColor;?>;
}
</style>
<div id="mt_instagram" class="block block-subscribe">
<div class="row">
<div class="left-newletters col-lg-8 col-md-8 col-sm-8 col-xs-8">
<div class="block-title">
<strong><span><?php echo $this->__('Join our Mail List Through Instagram!') ?></span></strong>
</div>
<div class="row-none">
<div class="popup_message">
<div class="intro">
<?php echo $desc; ?>
</div>
<form action="<?php echo Mage::getBaseUrl().'instagram/index/instagram_signup'; ?>" method="post" id="instagram-validate-detail">
<div class="block-content">
<div class="input-box">
<input name="instagram-email" type="text" id="mt-newsletter" placeholder="Enter your email id"
value="" class="input-text required-entry validate-email"/>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Subscribe') ?>"
class="button">
<span><span><?php echo $this->__('Subscribe') ?></span></span></button>
</div>
</div>
</div>
</form>
</div>
</div>
I am getting my custom form also..But the controller is not getting called and functionalists are not working, only I am getting the form.
Can anyone help Me?
This is my first ever answer on stackoverflow, I will try my best to explain.
To start with, let me brief you about the block calls in Magento; any particular type of Block(.php files in Block folder) has a corresponding content/template (.phtml in template folder) file to render the data fetched from Model (.php in Model folder).
In your layout (.xml for your module in layout folder), you have added a block that is of type (core/template) so it will call the file Mage_Core_Block_Template.php and can access all its methods. However, if you want to create a custom block you can update layout (instagram module) file like this.
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<instagram_index_instagram_signup>
<reference name="head">
<action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action>
</reference>
<reference name="content">
<block type="instagram/instagram" name="instagram.signup" template="instagramlogin/Instagram_signup.phtml"></block>
</reference>
</instagram_index_instagram_signup>
</layout>
And create a file in Block folder with name Blazedream_Instagram_Block_Instagram.php and then you will be able to call custom methods to the block template.
Ex.-
class Blazedream_Instagram_Block_Instagram extends Mage_Core_Block_Template
{
public function customMethod()
{
$response = array('a', 'b', 'c');
$this->getResponse()->setHeader('Content-type','application/json', true);
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
return;
}
}
Update you controller action call to
$this->loadLayout();
$this->renderLayout();
Now, to add this block inside another custom module, update its layout like
<fname_controller_action>
//path controller path on which you want to add/update the block
<update handle="my_custom_handle" />
</fname_controller_action>
<my_custom_handle>
<reference name="content">
<reference name="where_you_want_to_add">
<block type="instagram/instagram" name="my.custom.block" as="instagram.signup" template="template_path/instagram.phtml"/>
</reference>
</reference>
</my_custom_handle>
or add a constructor inside the block file Blazedream_Instagram_Block_Instagram.php like -
public function __construct()
{
parent::__construct();
$this->setTemplate('template/instagram.phtml');
}
and call the block in any template file with the below code
echo $this->getLayout()->createBlock('instagram/instagram')->toHtml();
You might need to update your layout file in this case.
If you do everything correctly, you should be able to call $this->customMethod() in the template file instagram.phtml
Thanks! Pardon me if I could not explained it properly.
Related
I'm working on a magento ecommerce, I'm not the one who configured it or anything, I'm just doing his CSS, however, the site does not display the breadcrumbs.
Inside the "page / html / breadcrumbs.phtml" file I made a var_dump in the $ crumbs variable and it is always empty.
In the XML only in one situation the breadcrumbs is displayed in the frontend, when I enter the code inside the "default" tag if I put this code inside "customer_account_login" nothing will be displayed on the front.
Code of breadcrumbs.phtml:
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Here part of code of "customer.xml"
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<!-- Mage_Customer -->
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
</reference>
<!-- HERE BREADCRUMBS DISPLAYS ON ALL PAGES THE SAME CONTENT "HOME / MY ACCOUNT" -->
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>My Account</crumbName>
<crumbInfo><label>My Account</label><title>My Account</title><link>/customer/account/</link></crumbInfo>
</action>
</reference>
</default>
<!-- Load this update on every page when customer is logged in -->
<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
</reference>
</customer_logged_in>
<!-- Load this update on every page when customer is logged out -->
<customer_logged_out>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
</reference>
<remove name="reorder"></remove>
</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="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>
If I move the breadcrumbs code from "< default >" to the "< customer_account_login translate="label" >" for example, all screens returns the breadcrumbs as null.
I have no idea what's going on. I just wish all the screens had their breadcrumbs being displayed.
Check that breadcrumbs are actually enabled in the back end admin panel like below.
I just created a cms block from magento admin panel and now I want to get it into the phtml I tried this way:
<?php
$currentview = Mage::app()->getStore()->getCode();
if($currentview = 'default'){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1')->toHtml();
}
else if($currentview = 'it'){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
}
?>
I am getting cms block but if statement not working how can I make it working ?
If you have created CMS block named ostore_footerb1-it from admin panel.
Then following will be code to call them in .phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
?>
Another way to do this is :
In the layout (app/design/frontend/your_theme/layout/default.xml):
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="cms_ostore_footerb1-it" as="cms_newest_product">
<action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
</block>
</reference>
</cms_page>
</default>
In your phtml template:
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
To get static block in phtml file
echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
Try this:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml(); ?>
Or this:
add this piece to the layout:
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="ostore_footerb1-it" as="ostore_footerb1-it">
<action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
</block>
</reference>
</cms_page>
</default>
and call in phtml
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
if I have a template in
app\design\frontend\base\default\template\dir\template.phtml
that look like this
<div class='block block-list'>
<div class='block-title'><strong><span>Some Block</span></strong></div>
<div class='block-content'>
<?php echo "my content"; ?>
</div>
</div>
How can I show it on a catalog page using local.xml? Shouldn't this code work?
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="right">
<block type="core/template"
name="somename"
template="dir/template.phtml" />
</reference>
</default>
</layout>
I think you can not have custom layout handle<catalog_category_default translate="label"> inside default layout handle<default>
Correct me if I am wrong.
You have to use template reference name before that reference tag.
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<catalog_category_default translate="label">
<reference name="right">
<block type="core/template"
name="somename"
template="dir/template.phtml" />
</reference>
</catalog_category_default>
</default>
</layout>
I'm trying to move magentos advanced search link from the footer links right beneath the search bar.
I know that the origins of the link are in layout/catalogsearch.xml under
reference name="footer_links" and appear in the footer because of getChildHtml('footer_links') in footer.phtml
And i know that the search bar originates from template/catalogsearch/form.mini.phtml and appears though catalogsearch.xml under reference name="top.menu"
Any ideas on how to proceed here?
thank you for the quick answer!
But it is not exactly what I was looking for as it would display the entire footer links block beneath the searchbar.
Nevertheless thank you for showing me the method you used for that!
Anyways, I figured out a solution on my own:
I modified catalogsearch.xml:
<default>
<reference name="top.menu">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
<!-- add a new reference to top.search including my new adv.search block -->
<reference name="top.search">
<block type="page/template_links" name="adv.search" as="adv.search" >
<action method="addLink" translate="label title" module="catalogsearch">
<label>Advanced Search</label>
<url helper="catalogsearch/getAdvancedSearchUrl" />
<title>Advanced Search</title>
</action>
</block>
</reference>
<!-- the reference to the footer i commented out as its not longer needed; it includes advanced search and popular search terms-->
</default>
In form.mini.phtml I added a new div that calls adv.search:
</script>
<div class="adv-search"> <?php echo $this->getChildHtml('adv.search') ?> </div>
</div>
And last, in styles.css, I added some code to controll the looks of that div:
.adv-search {width:100px; height:15px; margin-top:24px; margin-left: 120px;}
.adv-search a { color:#fff; font-weight:bold; }
any additional advice is more than welcome
Cheers!
In order for this to work, you must:
1) Update your app/design/frontend/[yourtheme]/default/layout/local.xml file
2) Call the new blocks in app/design/frontend/[yourtheme]/default/template/page/html/header.phtml - this is needed because header.phtml is not a "core/text_list" block type which automatically renders its nested blocks. So we must explicitly tell Magento to render those child blocks
Your app/design/frontend/[yourtheme]/default/layout/local.xml should contain this:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<!-- Insert cms links. No need to use <action method="insert"> as this block is not used elsewhere in layout -->
<block type="cms/block" name="top_links_cms" as="top_links_cms" before="top_links_other">
<action method="setBlockId"><block_id>footer_links</block_id></action>
</block>
<!-- Insert former footer links. -->
<action method="insert">
<!-- We must keep block name "footer_links" as it is used as a reference for adding links by other modules -->
<blockName>footer_links</blockName>
<!-- Name of the block we want to have as sibling (in order to get its position and place our block after it. See next node <after> -->
<siblingName>topSearch</siblingName>
<!-- $after param from Mage_Core_Block_Abstract::insert() is a boolean type, so its value in the XML node is [empty], 0 or 1 -->
<after>1</after>
<alias>top_links_other</alias>
</action>
</reference>
<reference name="footer">
<action method="unsetChild"><name>footer_links</name></action>
<action method="unsetChild"><name>cms_footer_links</name></action>
</reference>
</default>
</layout>
This is an updated header.phtml you can get inspiration from for your app/design/frontend/[yourtheme]/default/template/page/html/header.phtml file:
<div class="header-container">
<div class="header">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></h1>
<?php else:?>
<strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
<?php endif?>
<div class="quick-access">
<?php echo $this->getChildHtml('topSearch') ?>
<?php
/**
* Add other top links (footer and cms links)
*/
?>
<?php echo $this->getChildHtml('top_links_cms') ?>
<?php echo $this->getChildHtml('top_links_other') ?>
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
</div>
</div>
<?php echo $this->getChildHtml('topMenu') ?>
I am trying to place a new phtml block at a specific place within another phtml page and I am not getting the results I expected - any advice would be much appreciated.
Specifically, I created a new childHtml block for the cart page in my module's xml layout file:
<layout version="0.1.0">
<checkout_cart_index>
<reference name="head">
<action method="addJs"><script>varien/product.js</script></action>
<action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>
<reference name="content">
<block type="delivery/frontend_checkout_cart_delivery" name="delivery.container" as="delivery" template="unleaded/delivery/checkout/cart/shipping/delivery.phtml"/>
<block type="core/html_calendar" name="delivery_html_calendar" as="delivery_html_calendar" template="page/js/calendar.phtml"/>
</reference>
</checkout_cart_index>
</layout>
Next I made a call to $this->getChildHtml('delivery') in my modified checkout/cart/shipping.phtml template where I wanted it placed:
....
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
....
<?php foreach ($_rates as $_rate): ?>
....
<li>
<?php if ($_rate->getCode() == 'delivery'): ?>
<?php echo $this->getChildHtml('delivery'); ?>
<?php endif; ?>
</li>
....
<?php endforeach; ?>
....
<?php endforeach; ?>
....
What I wanted / expected was to see my block output where I inserted it, but instead it is being output at the very bottom of the page (see screenshot). I am almost certain my mistake is an xml / layout based mistake, but I don't know what?
You call getChildHtml() from within the checkout.cart.shipping block, but add your new block to content. Instead of,
<reference name="content">
...you simply need to say which block your new one will be the child of.
<reference name="checkout.cart.shipping">