0

I've injected custom variable named slider_id to my block like below,

    <reference name="content">
         <block type="sliderpro/sliderpro" name="defaultslider" as="defaultslider" before="-" template="sliderpro/defaultslider.phtml" >
               <action method="setData"><name>slider_id</name><value>1</value></action>
         </block>
         <block type="sliderpro/sliderpro" name="defaultslider" as="defaultslider" before="-" template="sliderpro/defaultslider.phtml" >
                <action method="setData"><name>slider_id</name><value>3</value></action>
          </block>
     </reference>

Under defaultslider.phtml,

echo $this->getSliderID(); // Outputs 3

I need to grab both the requested slider_id's i,e 1 & 3.

Any idea how to achieve this ?

1 Answer 1

2

You can do this:

<reference name="content">
     <block type="sliderpro/sliderpro" name="defaultslider" as="defaultslider" before="-" template="sliderpro/defaultslider.phtml" >
           <action method="setData"><name>slider_id</name><value>1,3</value></action>
     </block>
 </reference>

Then get the slider ids like this:

$sliderIds = explode(',', $this->getSliderId());

Then you will always have an array with ids even i you set the value to 1 or 1,3.

[EDIT]
If you want 2 sliders on the page with 2 different ids, just give different names to the sliders in the xml.

<reference name="content">
     <block type="sliderpro/sliderpro" name="defaultslider" as="defaultslider" before="-" template="sliderpro/defaultslider.phtml" >
           <action method="setData"><name>slider_id</name><value>1</value></action>
     </block>
     <block type="sliderpro/sliderpro" name="defaultslider_1" as="defaultslider_1" before="-" template="sliderpro/defaultslider.phtml" >
            <action method="setData"><name>slider_id</name><value>3</value></action>
      </block>
 </reference>
3
  • Thats absolutely right, but i'm creating a slider module which gives unique block type on addition of every slider, user will grab and paste it on any page to display it. So i think this might confuse my client. Is there any other option ? Jun 9, 2015 at 7:42
  • @Vinoth. See my update.
    – Marius
    Jun 9, 2015 at 7:51
  • Yes It worked... Jun 9, 2015 at 10:20

Your Answer

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

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