Link to home
Start Free TrialLog in
Avatar of www_puertoricoautoforo_com
www_puertoricoautoforo_comFlag for United States of America

asked on

Magento CMS > Echo variables in CMS? How? {{product name}} etc.. Product page.

I'm editing a CMS block that appears in the bottom portion of every product page.  It's just going to be a bunch of test and <ul>'s with SEO text.  Now I have the CMS text working just fine, I love it! My problem is that I want to repeat relevant keywords in my text, but I need to reference these keywords dynamically.  If it was just normal PHP in zencart I would have something like this...

echo = "<p>This is a great product for your $category \. You can use the $product everyday when you get out of bed or to clean your kitchen floor \.  We all know that shopping for $category can be a hard task, rest assured that purchasing  $product   is a risk-free purchase since it's covered by our warranty. blah blah blah </p>";

But since I'm using a CMS block I have to have {{product}} type of things.. which I know nothing about.. Can I call these {{variables}} like product name and category from a CMS block? If so how?  Thanks!



\app\design\frontend\default\MYTEMPLATE\template\catalog\product\view.phtml



<ul>
<li>SEO STUFF, blah blah blah</li>
<li><a href="{{store url=""}}about-magento-demo-store">About Us</a></li>
<li>Manufacturer:  $_product->getAttributeText('manufacturer'); </li>
<li class="last"><a href="{{store url=""}}customer-service">Customer Service</a></li>
</ul>
Avatar of miked2004
miked2004
Flag of United States of America image

Lets see if this gets you off to a good start:

In the code snippet I show how to echo out a cms block and echo a template file . I believe the later will help you more.
You can just retrieve the registered product in the template file and access all the product data and not have to worry about special template like you would on a cms block.

<?php
//echo out a cms block
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ID_FROM_CMS')->toHtml(); 

//This might work to inject the product name.
echo $this->getLayout()->createBlock('cms/block')
->setBlockId('ID_FROM_CMS')
->setProduct($productName)
->toHtml(); 

//or just create a file that pulls the registered product and do with it is you will.
//This is how to echo a template file into a page
echo $this->getLayout()->createBlock(page/html)->setTemplate('path/to/template/file')->toHtml();

Open in new window

Actually use this for that last piece of code instead
echo $this->getLayout()->createBlock('core/template')->setTemplate('path/to/template/file')->toHtml();

Open in new window

Avatar of www_puertoricoautoforo_com

ASKER

I get errors when trying either of these, is there another step that I should add to this?

I tried putting both of these scripts in the bottom of my view.phtml file..

Is there a way I can display the product name in one of my CMS blocks?
ASKER CERTIFIED SOLUTION
Avatar of miked2004
miked2004
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't believe there a convent way to display the products name in a cms block. This is a very simple way to do the same thing. You have much more control this way and can use php. The only down side is it is not editable in the admin, but for what you are doing it sounds like once you get it set up you will not need to adjust it from the admin.
P.S. You should post your error messages if you get them.