Magento: how to add content to <?php echo $this->getChildHtml('outer-right') ?> - magento

I'm still struggling with magento.
I have a 3 column layout but want to place yet another
widget in the outer right of the content with
<?php echo $this->getChildHtml('outer-right') ?> .
How do I create a .phtml file with the stuff to be output
when <?php echo $this->getChildHtml('outer-right') ?>
is invoked?
Thanks.

You just need to add/stuff your blocks via your layout.xml file inside a block called 'outer-right' in the correct layout handle. When your layout handle is active you will be able to fetch its html by getChildHtml('outer-right')
<cms_index_index>
<block type="core/template" name="outer-right" template="xyz.phtml">
<block type="core/template" name="inside-outer-right-1" template="inside.phtml"/>
<block type="core/template" name="inside-outer-right-2" template="inside2.phtml"/>
</block>
</cms_index_index>

Related

Magento : add external code to product view page

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

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 Shortcode CMS block not working on product pages

I am attempting to add a CMS block on a Magento product page.
The shortcode which I am using is:
{{block type="cms/block" block_id="myproductblock"}}
The block shows up as text. It does not insert the CMS block. I have made sure that the WYSIWYG editor is disabled.
I assume you want to add it to product.phtml
To do this, you need to edit the layout/catalog.xml
...
<catalog_product_view>
..
...
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<!-- start your code: -->
<block type="cms/block" name="myproductblock" before="-">
<action method="setBlockId"><block_id>myproductblock</block_id></action>
</block>
Then inside your view.phtml you write:
<?php echo $this->getChildHtml("myproductblock") ?>
Where the "myproductblock" is the same as the name you specified inside the layout.xml
After this you have to clear the layout.xml cache and it should work :)
Why your code didn't work:
Those .phtml files all are php-scripts.. the "{{" and "}}" must interpreted by a template engine and is only valid inside emails, CMS pages/blocks and the wysiwyg editors in the backend.

Magento - moving extension from left/right column to main

I try to move an ext: Customers who bought this product also purchased from default left/right column to main column under the product, but I don't know how to do this.
I try to change the line <product_detail_leftposition translate="label"> to <product_page translate="label"> in system.xml file but it doesn't help.
Any suggestions?
Thanks for any help!
You can do this by adding it to the Products view page section inside your layout XML. Add the block inside the content reference block, somewhere at the bottom.
Make sure it's inside the handle as this defines the structure used on the product view page.
app/design/frontend/[namespace]/[themename]/layout/catalog.xml
<catalog_product_view translate="label">
...
<reference name="content">
...
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<!-- Other blocks etc here.. add at the bottom -->
<block type="module/block" name="yourblock" as="yourblock" />
</block>
</reference>
</catalog_product_view>
This should automatically output the block for you if you add it in here, although that depends on the theme you are using.
if it doesn't automatically show, you may need to add a line to your view to display the block:
app/design/frontend/[namespace]/[themename]/template/catalog/product/view.phtml
<?php // use the block name used in the XML config.. ?>
<?php echo $this->getChildHtml('yourblock') ?>

looking to show product reviews in sidebar on product page magento

I'm looking to show the most recent reviews for a product (maybe 3 or 4) in the sidebar on that products page in magento.
Showing the first 10 or 15 words of the review, the star bar and a link to the reviews page to see all the reviews..
any advice or pointers greatly appreciated,
Thanks,
Johnny
As ElGabby said, creating a extension would be the way to go.
But you can do this by editing your current layout.
Go to the file catalog.xml in /app/design/frontend/default/[your theme]/layout/ or /app/design/frontend/base/[your theme]/layout/
find the section:
<catalog_product_view>
in there you proberly have a section like:
<reference name="right">
in that section add:
<block type="review/product_view" name="right.rewiev" template="review/rightbar.phtml" />
the section in my example look like this:
<reference name="right">
<block type="review/product_view" name="right.rewiev" template="review/rightbar.phtml" />
<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
</reference>
save the file and create a new file in:
/app/design/frontend/default/[your theme]/design/review/rightbar.phtml
content of that file would be something like:
<?php $collection = $this->getReviewsCollection(); ?>
<?php if(count($collection) > 0):?>
<?php foreach ($collection as $rating):?>
<?php echo $rating->title //title of the rewiev?>
<?php echo $rating->detail //content of the rewiev?>
<?php echo $rating->created_at //data rewiev is created?>
<?php endforeach;?>
<?php endif;?>
I would create an extension.
Using layout.xml place your block that should extend core/template block in left/right sidebar of the product page
Within that block class you should have methods that will retrieve from the database the reviews you wish to display. So say for instance you would need a method getReviews()
In the template call $this->getReviews() and iterate the result and display the reviews as you would like. The star bar might be a bit of a hassle but if you look at other template files where they are used you should be able to get the gist of it :)
HTH :)

Resources