I have an observer "checkout_cart_add_product_complete"
I want to render the content of cart.phtml in observer and controller which is located in /template/ajaxminicart/checkout/cart.phtml
How can i do this?
Check following,
<?php
$newBlock =Mage::app()->getLayout()
->createBlock('checkout/cart')
->setTemplate('ajaxminicart/checkout/cart.phtml')
-->toHtml();
echo $newBlock;
?>
Related
I'm using codeigniter 3x. I'm working on my website. I'm using include method in my view.
Like
<?php include('templates/header.php'); ?>
<h1>Home Page</h1>
<?php include('templates/footer.php'); ?>
Is this a good way to show header and footer in codeigniter.
Thank!
You are half your way, here is how you will be able to make it more dynamic, in your views file you should have a structure like this:
views
- header.php
- footer.php
- template.php
- home.page
In header.php you should have all your header and footer content which you wants to display on all pages.
Now in your template move all your includes.
template.php
<?php $this->load->view("header.php"); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view("footer.php"); ?>
here you notice $main_content variable, it is dynamic file name which we want to load in our controller. So lets assume you have a controller like this:
public function home()
{
$data['meta_title'] = $this->lang->line('home_meta_title');
$data['meta_description'] = $this->lang->line('home_meta_description');
$data['meta_keywords'] = $this->lang->line('home_meta_keywords');
$data['main_content'] = 'home';
$this->load->view('template',$data);
}
$data['main_content'] = 'home'; is loading your home.php file, you can also load from subdirectories like 'directory/home'. You can also pass any variable like I gave you above example with dynamic meta.
I want to show message on some condition in a template file(custom module template file).I am having following code.
<?php
if(count($collection)): ?>
<?php foreach($collection as $coll): ?>
some calculations
<?php endforeach; ?>
<?php else: ?>
<?php $message = $this->__('There is no data available'); ?>
<?php echo Mage::getSingleton('core/session')->addNotice($message);?>
<?php endif;?>
But this is not working properly. The message is displayed on other pages not on the same page.
If you really need to implement that right in the template, you may use the code below:
<?php echo $this->getLayout()->createBlock('core/messages')->addNotice('My Message')->toHtml(); ?>
But the solution described by Amit Bera sounds like a better way to resolve it.
Muk,According to your code
Mage::getSingleton('core/session')->addNotice($message);
add an notice to magento.This is code set notice to session and which is reflecting on page refresh according php session ,a session variable set value is reflecting after page refresh.
If you already added this notice on other page before came to your file then ,you need to add core/session to custom module template file controllers file.
Code is $this->_initLayoutMessages('core/session');
In controller you need below code in controller.
/* load the layout from xml */
$this->loadLayout();
$this->_initLayoutMessages('core/session');
/* rendering layout */
$this->renderLayout();
Read more at inchoo blog
I found that $this->loadLayout() is what reads and clears messages from the session, therefore if you add messages before calling $this->loadLayout() then those messages should be displayed on the current page.
Example:
public function chooseFileAction() {
// a quick and dirty way to find the larger out of post_max_size and upload_max_filesize
$post_max_size = ini_get('post_max_size'); $post_max_size_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $post_max_size)));
$upload_max_filesize = ini_get('upload_max_filesize'); $upload_max_filesize_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $upload_max_filesize)));
$maxsize = $post_max_size_int < $upload_max_filesize_int ? $post_max_size : $upload_max_filesize;
// display max file size to user in a message box
$msg = 'Max file size: ' . $maxsize;
Mage::getSingleton('core/session')->addNotice($msg);
$this->loadLayout();
$this->_title($this->__('Catalog'))->_title($this->__('File Upload'));
$this->_setActiveMenu('catalog/customfileupload');
$block = $this->getLayout()->createBlock('customfileupload/adminhtml_customfileupload_choosefile');
$this->_addContent($block);
$this->renderLayout();
}
Caveat: this is tested in Magento 1.9, not 1.7.
First of all this concerns magento.
I want to have a newsletter with a standard header and footer. This header and footer are being built through static blocks.
How can i add a dynamic unsubscribe option in the static footer block? (an unsubscribe per customer)
And should this not be possible, how can I do it through other means?
Any help would be most welcome.
First create a static block and call phtml from static block
The code of .phtml file
call in a phtml file in static block
{{block type="core/template" template="newsletter/unsci.phtml"
name="newsletterall" }}
Create a phtml in unsci.phtml under app/design/frontend/yourpackage/youtemplate/newsletter
Call a static block like the code is below-
If you want only to unsubscribe then you should add below code in phtml file
<?php $subscriber = Mage::getModel('newsletter/subscriber')
->loadByEmail("dev.amit.bera#gmail.com")
if( $subscriber->getId()){
$unscibeurl=Mage::helper('newsletter')->getUnsubscribeUrl($subscriber); ?>
Un subcribe
<?php } ?>
Call static block in anywhere using below code
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($indenfirename)->toHtml(); ?>
I want to create custom category attributes dynamically(through Form) in admin.
I mean, how can I create custom category attributes through Model/Controller class?
Please suggest me proper solution to resolve this issue.
Thanks in advance!
Maybe this free extension will help you.
I Use it on Magento 1.9
Case: At backend I Created an attribute with Attributecode : category_custom_attribute
To display on category : edit /app/design/frontend/your-template/your-template/template/catalog/category/view.phtml
<?php $category = Mage::registry('current_category'); ?>
<?php $CatCustomAttribute = $category->getCategory_custom_attribute(); ?>
<?php echo $CatCustomAttribute; ?>
I know that you can call a cms block directly from a template file using the following:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml() ?>
Is there some way to do this with widget instances?
In your template:
<?php
$filter = Mage::getModel('widget/template_filter');
echo $filter->filter('{{widget type="cms/widget_page_link" template="cms/widget/link/link_block.phtml" page_id="2"}}');
?>
Andrew missed toHtml() function at the end:
<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2)->toHtml(); ?>
To know the correct parameters "type", "template" and more, you can use the "Insert widget" button on the graphical editor in a block/page template, then you click the show/hide editor and you get the code
The answer above may work, but the same thing can be achieved by loading the widget as you would a static block and passing in the custom parameters using the magic setters like this:
<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2); ?>