2

I need to set some tags(title, description) after i render a layout. I know how to set the titles via layout files:

<reference name="head">
 <action method="setTitle" translate="title"><title>Your Title</title></action> 
</reference>

or via code by accessing head block element and calling setTitle('your title') method on it

$this->getLayout()->getBlock('head')->setTitle('your title'); 

but i need the titles to be dynamically fetched from an item from a collection.

If i go with the controller approach i will be loading the same element twice since i need to load the product to get the fields to set them as Title and Description and again in the block to show it in the product page.

Is it wise to save it with Mage::register('variable', 'value');? Should i create the entire layout programatically and assign the data with $this->getLayout()->getBlock('your.block.name.in.the.layout')->assign('data', $data);?

0

When you are talking about a product, you should try to get the product before the renderLayout call, to access the head block and get the product from Mage::registry('product') or Mage::registry('current_product')

| improve this answer | |
  • 1
    This particular case is not a product, but the idea is pretty much the same. It's a custom collection. – mbalparda Jul 28 '14 at 7:14
1

You can assign a new block without template in the content, that is loaded after the collection. In this block get all necessary information by getting data from main block (like product) or registry. Then call getBlock('head')->setTitle('your title'); from _prepareLayout

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.