I want to pass a variable with the block code like of JSON type in magento,
{{block type="multibanners/multibanners" category_id="9" name="multibanners" alias="multibanners" template="multibanners/multibanners.phtml"}}
from cms pages content area , but I don't receive any thing.
If I use block with action method than I easily get my value.
Anyone know how can I pass variable with my custom block?
When adding block on a cms pages remove style from block code.
To get the category_id in your phtml or Block use
$this->getCategoryId()
.I think the problem here stems from the block type you are calling. When you define a type, you're telling Magento to load that model and pass it the appropriate data - which then only exposes the functions defined on that specific model.
A better solution may be to reference the core block type "core/template" which exposes the ->getData() method, and then load the "multibanners/multibanners" model to work with and output the data.
I'm not sure what the proper syntax is to load 'multibanners', but in the multibanners.phtml would be something like this:
I found this very useful and I thought I'd explain what I did in case it helps anyone else.
I have a few static blocks that I use to build some static pages with basic non-changing information (about-us type pages) which include some photos. The photos are very large (for a web page) and I wanted to use Magento's resizing facility. The only way I could work out to do this was to use the ideas here. I now have a block I can include on any cms static page/block when I want to have a resized image with several parameters. It's like a subroutine (am I allowed to say that?! ;o). Anyway, here's what I did.
The block:
and the phtml code file:
Note I save my re-sized images in a resized folder and add the new size to the image filename so I can easily see what's happening and manage the files.
Thanks for reading!
I'm not 100% sure what you are asking, but if you are trying to pass a variable to
multibanners.phtml
from the code above then you could create another attribute similar tocategory_id="9"
and inmultibanners.phtml
you could get the value using$this->getData("category_id");
e.g.
In
multibanners.phtml
: