Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 3
Moving the product title to the 2columns-left template
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

I need my product title above as shown here: http://minervapromotions.com/gladrag/sucka-free.html

But when I move it from template/catalog/product/view.phtml to template/page/2columns-left.phtml by inserting this code:

<div class="middle layout-2columns">
               
<?php $_product=$this->getProduct() ?>
               
<div class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></div>
               <
div class="col-left sidebar" id="col-left">
...

then I get the following error:

Fatal errorCall to a member function getName() on a non-object

Any ideas what is not linking up correctly?

 
Magento Community Magento Community
Magento Community
Magento Community
 
dan_w
Sr. Member
 
Total Posts:  290
Joined:  2008-01-04
 

I think the problem you are running into is that getProduct and subsequently getName aren’t used in the models/blocks that control the page template files, so they can’t be called explicitly from those templates.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

Thanks for confirming, that’s what I thought - now I need to find a way to make them available there.

Time for me to play in the code some more. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

You need to create a new product block in 2columns-left.phtml to do this.

In layout/catalog.xml, find <catalog_product_view>. Under <reference name="root"> add this:

<block type="catalog/product_view" name="product.header" template="catalog/product/productheader.phtml" as="productheader"/>

Then, create the file template/catalog/product/productheader.phtml and put in your code:

<?php $_product=$this->getProduct() ?>
<div class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></div>
 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

@Anders:  Thanks for responding ... that didn’t create any errors - but it didn’t display it, either.  I must’ve missed something ...

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Oh, I forgot in 2columns-left.phtml, you have to add:

<?php echo $this->getChildHtml('productheader'?>

where you want the product header to appear.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

Beautiful.  Thanks so much!

 
Magento Community Magento Community
Magento Community
Magento Community
 
andrewg
Member
 
Avatar
Total Posts:  34
Joined:  2008-07-23
New York
 

I was wondering how i would do the same except for the category name. Im sure i just need to substitute a few things, but im unsure of the actual calls i need to make.

 
Magento Community Magento Community
Magento Community
Magento Community
 
andrewg
Member
 
Avatar
Total Posts:  34
Joined:  2008-07-23
New York
 

does anyone know? I keep getting errors when i try to put in this

<?php $_category=$this->getCurrentCategory() ?>
<div class="product-name2" id="product-name2"><?php echo $this->htmlEscape($_category->getName()) ?></div>
 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

andrewg:
Where are you putting that code? You need to put it in a template controlled by a category view block. Look at the code above, where we created a product view block for sherrie’s product code.

 
Magento Community Magento Community
Magento Community
Magento Community
 
andrewg
Member
 
Avatar
Total Posts:  34
Joined:  2008-07-23
New York
 

im putting it in template/catalog/category/

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Please explain what you want to accomplish.

- On which page(s) do you want a category name to appear? Catalog page? Product view page?
- In what part of the page do you want a category name to appear? Content? Left column?

 
Magento Community Magento Community
Magento Community
Magento Community
 
andrewg
Member
 
Avatar
Total Posts:  34
Joined:  2008-07-23
New York
 

i would like the name to appear on both the category page and the product page. And i want to put it in the left column.

thank you for the help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Create app/design/frontend/default/default/template/catalog/category/left.phtml containing this:

<?php
if (Mage::registry('current_category'))
{
    
echo $this->htmlEscape(Mage::registry('current_category')->getName());
}

In app/design/frontend/default/default/layout/catalog.xml, add this:

<block type="core/template" name="category.leftinfo" template="catalog/category/left.phtml" />

under reference “left” in the following page nodes:

- catalog_category_default
- catalog_category_layered
- catalog_product_view

Note that the category name might not display on the product page, because a product can be accessed through several categories or directly through no category.

 
Magento Community Magento Community
Magento Community
Magento Community
 
andrewg
Member
 
Avatar
Total Posts:  34
Joined:  2008-07-23
New York
 

thank you very much, i will try this now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
andrewg
Member
 
Avatar
Total Posts:  34
Joined:  2008-07-23
New York
 

It works! Now to add css elements and put it at the top of the page.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3