How to print an EAV-value in email template - php

I've introduced a custom EAV attribute for the customer object. Let's call it myvalue. Within several places in magento, I'm printing the value like this:
echo Mage::getSingleton('customer/session')->getCustomer()->getMyvalue();
Now, I'd like to print it to the order confirmation email template. How can I do that?

I've found the solution.
First, I created a new directory mydirectory in app/design/frontend/base/default/template/. In this directory, I put a file myvalue.phtml with the following content.
<?php
$customer=$this->getData('order')->getCustomer();
print_r($customer->getMyvalue());
?>
And I've included this block in the email template using this line:
{{block type='core/template' area='frontend' template='mydirecory/myvalue.phtml' order=$order}}

Related

How to display webform in drupal 7 views

I created webform as block and I'm rendering in template like:
<?php print render($page['contact_us']); ?>
This working fine in .php, but in views not working.
I would say that you are rendering region that contains your block, not the block it self and you placed that block in "contact_us" region. But regions are available only in your page template.
Check out how to render block directly:
https://www.drupal.org/node/26502
So, it should be like:
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block['content']);
And module name should be "webform". You can place this code directly in your view template, where you want your webform block rendered or in pre-precess function and then pass to your template as some variable and print it there.

How to use shortcode in Magento phtml page

I have a short code
{{block type="ibtheme/product_list_featured" category_id="51" random_products="" template="catalog/product/list/featured.phtml"}}
which is working fine in editor from backend. How can U call the same short-code from a PHTML page ?
When I put the same code, it is printing a simple text.
phtml is php code, not cms html passed through a filter to catch the short codes (macros) and expand them out.
The contents between "{{" and "}}" must interpreted by a template engine and is only valid inside emails, CMS pages/blocks and the wysiwyg editors in the backend.
You put their equivalent into layout and call them as in the following ->
Magento Shortcode CMS block not working on product pages
In Magento CMS or Static block, if you want to add PHP code then you can just call any custom .phtml file by using following code. Like here I am including my_custom.phtml.
{{block type="core/template" name="myCustom" template="cms/my_custom.phtml"}}
This is equivalent to following layout tag:
<block type="core/template" name="myCustom" template="cms/my_custom.phtml">
Hope you find it useful.
The above answers are both incorrect if I'm reading that you would like to use shortcodes in phtml pages. I use these frequently, since we have a tremendous amount of content, and breaking them down in to phtml blocks is the easiest way for us to keep our content fresh.
Anyhow, here's the correct way to use call blocks in phtml:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('cms/my_custom.phtml')->toHtml(); ?>
For Example, to use the block in your original answer would be
<?php echo $this->getLayout()->createBlock('ibtheme/product_list_featured')->setTemplate('catalog/product/list/featured.phtml')->toHtml(); ?>
I think this is what you're actually looking for. The code is in the CMS module in the Magento code.
<?php
// Load the cms helper
$helper = Mage::helper('cms');
// get the cms static block processor
$processor = $helper->getBlockTemplateProcessor();
// run the content with the shortcode through the filter
// in this case $item->getAnswer() contains a shortcode
$html = $processor->filter($item->getAnswer());
// print it to the page
echo $html;
?>
Remember anything is possible, just dig deeper. If in doubt, copy the Magento core code.

Use magento CMS block code in template files

This is the first time I am creating a custom tempalte for Magento. I installed a 3rd party plugin, that allows me to use this code in the cms editor:
{{block type='bannerslider/bannerslider' template='bannerslider/bannerslider.phtml'}}
Now, I want to use this on a page in my template. What php code should I use to get this to work ?
I tried
<?php echo $this->getChildHtml('bannerslider/bannerslider') ?>
But that displays nothing.
Thank you!
You have to declare your block inside layout file of your custom template (usually, local.xml) under some handle (like default or catalog_product_view).
For example:
<block type="bannerslider/bannerslider" name="banner_home" template="bannerslider/bannerslider.phtml"/>
under <default> handle would let you to call <?php echo $this->getChildHtml('banner_home') ?> in any place of your template. Notice that you have to use name from layout, not block class to call it with getChildHtml.
An alternative I received from someone else:
<?php echo $this->getLayout()->createBlock('bannerslider/bannerslider')->setTemplate('bannerslider/bannerslider.phtml')->toHtml();
?>

want to call one phtml file in another phtml file using anchor tag

I'm using Magento.
I want display and call one phtml file as a link in another phtml fileā€¦
I have the new.phtml file on the home page. On that I put one link CHECK ALL which display all new products as category page.. It looks like category page. For that I create another phtml file named newproductpage.phtml which has same code of new.phtml. Now I try to call this newproductpage.phtml file #homepage as CHECK ALL link for that I write this code....
CHECK ALL
But its not working....
thnx..
you call newproductpage.phtml in any phtml file using below code
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('custom/newproductpage.phtml')->toHtml(); ?>
Use the below code for rendering your phtml file in another phtml file.
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('templatefolderpath/filename.phtml')->toHtml(); ?>
For more refinement of your code, you can use the block name and block file name instead of core/template because core/template use the core resources.
You can not call directly one phtml file to another phtml file.
But there are two way to call your phtml file either create one controller and create one action and call action from your anchor tag or create one cms page which call your phtml file.
if you create one module, so in your layout file something you can write
<modulename_controllername_controlleraction>
<reference name="content">
<block type="catalog/product_new" template="custom/newproductpage.phtml" />
</reference>
</module_controllername_controlleraction>
Or you can directly put this code in your cms page content area
{{block type="catalog/product_new" template="custom/newproductpage.phtml"}}
and in anchor tag give cms page link.
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalog/product/new.phtml')->toHtml(); ?>
you can also check the link.
Display .phtml page in another .phtml page
I believe you and I want to do precisely the same thing. I'm creating a modal from bootstrap and I need to call in a partial using the href attr.
So far, I think this might be possible by creating a page in the CMS and then using something like this:
<li>Home</li>
But honestly, I'm just starting out with Magento and know very little.
you can use iframe for same and load this another page content using AJAX call

BannerSlider Extension

I'm using the BannerSlider Extension and it works great but for design purposes I need it to include it in a template.
At this moment I'm using it with the CMS like this:
{{block type='bannerslider/bannerslider' template='bannerslider/bannerslider.phtml'}}
How can I get the PHP code for that single line, to add it directly to my template ?
Create cms/block and place your code
{{block type='bannerslider/bannerslider' template='bannerslider/bannerslider.phtml'}}
and then you can call anywhere in template that cms/block like this
<?php
echo $this->getLayout()->createBlock('cms/block')->setBlockId('YOUR IDENTIFIER')->toHtml()
?>

Categories