0

In Magento 1, I want to do this: From Custom Layout Update, pass data via setData or some other way to a static block,

<reference name="left">
    <block type="cms/block" name="side_tabs" before="-">
        <action method="setData">
        <name>cms_target</name>
        <value>info_page</value><!-- url-key to a cms page -->
        </action>
        <action method="setBlockId"><block_id>side_tabs</block_id></action>
    </block>
</reference>

In a static block I want to use the passed data to customize the static block's functionality

 <a href="{{store url=''}}{{cms_target}}" target="_blank">

I know the above doesn't work. Is something similar to this possible?

The use case is customizing the static block's function depending on the category page it is displayed on.

3
  • Please, Explain explicitly what you want to do, where you want to display the value etc...
    – PЯINCƎ
    Dec 7, 2017 at 10:48
  • Clarified the post. Dec 7, 2017 at 11:17
  • I doubt this is possible without implementing something custom. Directives are rendered independently, i.e. not in the context of the cms/block class so a directive would never access getData on your cms/block class. You'd only be able to do this in code i.e. a phtml template, or a custom extended block of cms/block that switches out {{cms_target}} Dec 7, 2017 at 13:14

1 Answer 1

0

in my solution, you dont need the xml block

app/design/frontend/{package}/{theme}/template/custom/side_tabs.phtml

// Put your logic here to get the value as something like:

<?php 
$current_category = Mage::registry('current_category')->getId();
if ($current_category == "10") {
    echo "info_page";
} else {
    echo "info_page2";
}
   //you can also use a switch case if you want to display this value in many categories 

  switch ($current_category) {
      case 10:
          echo "info_page";
          break;
      case 11:
          echo "info_page2";
          break;
      case 12:
          echo "info_page3";
          break;
      default:
          echo "category-not-found";
          break;
  }
?>

Now in your static block, you can get value from the template like this:

{{block type="core/template" name="side_tabs" template="custom/side_tabs.phtml"}} 
2
  • This would be useless in my case. The point is the ability to add a link to a category page (say, /gadgets/gizmos), and the ability to set whichever cms page this link leads to on the custom layout update textarea. People who will actually be creating info pages and categories will not have access to the source code. Dec 7, 2017 at 13:56
  • Im not understanding what you want to do, but if you want to some info to your static block according to the current category, this will work. Good luck
    – PЯINCƎ
    Dec 7, 2017 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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