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

www_puertoricoautoforo_com used Ask the Experts™
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!


<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>
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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.

//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')

//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

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?
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

You are probably getting errors if the path to the template file does not exist or is incorrect.
Here is a little more detail.

You must create a template file. this file has the extension .phtml
The following code will show you how to echo out the template file and how to access the current product.
//IN /app/design/frontend/default/YOUR_TEMPLATE_PATH/catalog/product/view.phtml place the following code to echo out our block.
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalog/product/custom.phtml')->toHtml(); ?>

Now Create the file we are setting as the template. For my example it is a file in the same directory as the view.phtml file.
The following code will get the current product and echo out its Id. you can get any loaded properties for the product though.

$_product = Mage::registry("current_product");

Open in new window

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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial