Short of creating my own widget or block class to do so, is there a way to display a product's name, sku, price, or other property in a static block or CMS page?
If there isn't a way to do this out of the box, is there a well excepted way to achieve this?
That is, I'd like to be able to do something like this in a block or page
{{block type="some/block" sku="PRODUCT_SKU" variable_to_display="name"}}
and have the product's name appear in the static-block/page.
Does this exist in Magento's core? Somewhere in the community?
Best Answer
I'm not fully aware of a core means to go about this (I've not looked), but the following isn't particularly difficult to implement.
Just a few days ago, we needed the output from a helper - passed back into another helper, rendered via a CMS block.
This won't require
phtml
files to be created just for the sake of a single function - and will allow a fairly flexible use ofhelper
ormodel
methods to be executed.Whilst probably not the clean core solution you want, the output should be what you are after.
Calling Helper Methods
There is no fault tolerance in this (ie. checking a method/class even exists etc.); but if you really need it, you could modify it to suit.
What I wanted was to fetch the return value of a helper that got the minimum price of a bundle product; then push that output through the currency helper to format it appropriately.
Which was rendered using the following class.
Calling Model Methods
So tweaking the above code ever-so-slightly (I've stripped out the helper callback just to shorten the amount of code).
You could execute,
With the following supporting class,
This class was kept fairly generic and loading a whole method for one method would be heavy - but you can just tailor it to your needs.
Obviously something like this would be more lightweight, but you can tweak your methods to suit your needs.
Common Method
The referenced helper method above,
stringToBoolean
, was just the following: