Magento : add external code to product view page - magento

i have an external script in phtml and i wanna add it right under the price-box div
<layout version="0.1.0">
<catalog_product_view>
<reference name="content">
<reference name="product.info">
<block type="core/template" name="customprice" as="other" template="customprice/extJs.phtml"/>
</reference>
</reference>
</catalog_product_view>
</layout>
i have tried this in xml layout but it didn't work
any suggestion ?

the quick n dirty way, paste this in your view.phtml or whereever.
<?php echo $this->setTemplate('customprice/extJs.phtml')->toHtml(); ?>

First of all, no need for two reference when you are adding or updating some blocks locally.
Try this:
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="customprice" as="other" template="customprice/extJs.phtml"/>
</reference>
</catalog_product_view>
And in your view.phtml file call this where you want the block to appear
<?php echo $this->getChildHtml('other'); ?>

#James, there's no need to call the block defined as "other" explicitly. It is already defined in view.phtml

Related

Get a block type of a page Magento

I would like to know how to find the block type of some page example : the home page.
I have a problem in my homepage, I want to display some block, in the xml I declared my block in <cms_index_index> (local.xml) but if I put it in the <reference name="head"> it appears, if <reference name="content"> or <reference name="content"> it does not work . It seems to me that the type of block is not good.
xml:
<cms_index_index>
<reference name="root">
<block type="core/template" name="seconnecter_test" template="customer/form/test-seconnecter.phtml"/>
</reference>
</cms_index_index>
in the homepage 1column-full.phtml i called it like this:
<?php echo $this->getChildHtml('seconnecter_test');?>
You can use
<reference name="root">
<block type="core/template" name="seconnecter_test" output="toHtml" template="customer/form/test-seconnecter.phtml"/>
</reference>
When you give <reference name="content"> Their block type is core/text_list. this block type output their content automatically, you don't need to use getchildhtml().
In your local.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<cms_index_index>
<reference name="content">
<block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/>
</reference>
</cms_index_index>
</layout>
Place the template file at correct location, and the block will render at top of content.
Or try this go to cms->pages->homepage from admin panel. Add following in the layout update xml of design section
<reference name="content">
<block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/>
</reference>
refresh the cache.

How to place my custom block inside another block in Magento using layout xml?

first of all I want to say that I have searched for this whole day on te internet and could not find what I wanted. I am a newbie here as well, so please forgive me if I broke any rule.
I am trying to develop a module which will add videos to product page along with images. I am stuck in this concept:
How do I insert my block into an existing base block ? For example, in the product page, there is a block product.info. Inside this block there is "Availability", "Price" etc.
How do I insert my custom block just below "Availability" and above "Prices" using my module's layout xml and template.
So I am trying to achieve something like this using my module's layout file:
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
WRITE BLOCK HERE SO THAT MY BLOCK SHOWS BELOW AVAILABLITY
</reference>
</reference>
</catalog_product_view>
Is this possible ? or Do I have to override the core class Mage_Catalog_Block_Product_View to do this ?
PS: Basically my aim is to list my videos next to images. Right now, I am able to list my videos from module, but images don't come in that case. I used
<block type="myblock/myblock" name="somename" as="media" template="abc.phtml"/>
So I want to append my block to the existing content.
I solved it. I had to rewrite the Mage_Catalog_Block_Product_View_Media .
In my class I over-rid the function _toHtml function like this:
public function _toHtml()
{
$html = parent::_toHtml();
$html.=$this->getChildHtml('media_video');
return $html;
}
where "media_video" is my block. My layout xml file:
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<reference name="product.info.media">
<block type="myblock/myblock" name="somename" as="media_video" template="beta/abc.phtml"
before="-"/>
</reference>
</reference>
</reference>
</catalog_product_view>
You can add new block instead of over-right existing.
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<block type="myblock/myblock" name="somename" as="media_new" template="abc.phtml"/>
</reference>
</reference>
</catalog_product_view>
Get New Block using following code in phtml file
<?php echo $this->getChildHtml('media_new') ?>
Thanks
Note output="toHtml" in the below code. This will print your block in product.info section.
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<block type="myblock/myblock" name="somename" as="media"
template="abc.phtml" output="toHtml" before="-" />
</reference>
</reference>
</catalog_product_view>

how to display recently viewed products list on product details page - magento

I have used mobileshoppe theme for magento and trying to display recently viewed product list at product details page but some how its not working...
Added code below at catalog.xml
<catalog_product_view translate="label">
<reference name="content">
<block type="reports/product_viewed" name="product.recently.viewed" as="product_recently_viewed" template="reports/product_viewed.phtml"/>
</reference>
</catalog_product_view>
and below code at app\design\frontend\default\mobileshoppe\template\catalog\product\ view.phtml
<?php echo $this->getChildHtml('product_recently_viewed') ?>
I have tried the same with default theme and its also not working, can any one help me to figure out this issue ?
Thanks...
On the the product detail template (view.phtml) you have to be more specific in the xml where you want to place the block. See the example below using local.xml in the theme layout directory (app/design/frontend/your package/your theme/layout/local.xml) to insert the block. Here's an example from a site I'm working on. Ironically we are having problems with it displaying consistently, which I'm trying to figure out right now, but this is working most of the time! Try getting more specific in your catalog.xml and it should work. The xml is in local.xml, the echo is in catalog/product/view.phtml
<?php echo $this->getChildHtml('recently_viewed') ?>
<catalog_product_view>
<reference name="content">
<reference name="product.info">
<block type="reports/product_viewed" name="left.reports.product.viewed" template="reports/product_viewed.phtml" as="recently_viewed" />
</reference>
</reference>
Can you please replace xml reference content to left.
Instead of this
<reference name="content">
Use below and check
<reference name="left">
As it is a part of sidebar so it should work with left / right column as you want to display in page.
Cheers!

Magento: Change the block template in local.xml

I would like the product reviews page to use a different template instead of:
catalog/product/view.phtml
In review.xml, I see the file being called:
<block type="review/product_view" name="product.info" template="catalog/product/view.phtml">
Is there a way I can override that in local.xml and create a new file (ex: view2.phtml) and use that for this page?
<review_product_list>
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/view2.phtml</template></action>
</reference>
</review_product_list>
Yes, you can definitely do that by writing the following code in local.xml:-
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/view2.phtml</template></action>
</reference>
Here view2.phtml is your new file in the proper folder structure.
Hope it helps.

Magento: product specfic designs through 'Custom Layout Update'

If I want to control how each product is displayed (i.e. a custom design when specified) my first thought is to do this:
Create a custom view.phtml in template/catalog/product/my_view.phtml
Navigate in the admin to Product->Design->Custom Layout Update
Add this block:
<reference name="content">
<action method="setTemplate">
<template>catalog/product/view_print.phtml</template>
</action>
</reference>
But the template is never loaded, only the default view.phtml. Is this the correct method? I need to be able to do this in the product settings.
Found the answer:
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/NEW_VIEW.phtml</template></action>
</reference>
Navigate in the admin to Product->Design->Custom Layout Update > Add the below custom block. > It works for all the stores.
"<reference name="product.info">
<block type="namespace_modulename/catalog_product_list_custom"
name="catalog.product.modulename" as="modulename" after="tierprices"
template="modulename/catalog/product/modulename.phtml"/>
</reference> "
Add the below code in view.phtml
<?php echo $this->getChildHtml('modulename'); ?>

Resources