Jump to content

Looping Two dynamic variable through foreach loop on Prestashop module.tpl file


Recommended Posts

Dear Sir,

 

 I want to repeat below li item through looping on module.tpl file where below bold and italic part are two dynamic varibale item which come through module parameter area (Both parameters contain comma separated string).

 

 I want to explode that (Comma Separated String) on module.php file and loop it on module.tpl file.

 

<li><a href="#cubeRandom"><img src="images/example/002.jpg" class="cubeRandom" /></a>

<div class="label_text">

<p>cubeRandom</p>

</div>

</li>

Can you Please help me to achieve that.

 

I am able to looping one dynamic varible.But in case of two (which have to loop simultaneously) I m failed.

 

Please advice...

Link to comment
Share on other sites

{foreach from=$array_name item=itemname}

<li><a href="#cubeRandom"><img src="{$item.imagenamewhatever}" class="cubeRandom" /></a>
<div class="label_text">
<p>{$item.namewhateveritis}</p>
</div>
</li>

{foreach}

 

Make sure you reference those 'whateveritis' things using the array key of the php array

Link to comment
Share on other sites

'skitter_image1' => Configuration::get($this->name.'skitter_image'),

'skitter_label1' => Configuration::get($this->name.'skitter_label'),

 

I use Configuration::get to store array value and separate this vaule through explode function e.g below.

 


       $string1="".$skitter_image1."";

       $string2="".$skitter_label1."";

 

        $array1=explode("\n",$string1);

        $array2=explode("\n",$string2);

 

And assign array as below on mymodule.php file

 


$this->context->smarty->assign('myArray1',$array1);

$this->context->smarty->assign('myArray2',$array2);

 

Please advice how to write foreach loop on mymodule.tpl file to achieve below where italic portion comes from two array variable $myArray1 and $myArray2 

 


<li><a href="#cubeRandom"><img src="images/example/002.jpg" class="cubeRandom" /></a>

<div class="label_text">

<p>cubeRandom</p>

</div>

</li>



Link to comment
Share on other sites

'skitter_image1' => Configuration::get($this->name.'skitter_image'),

'skitter_label1' => Configuration::get($this->name.'skitter_label'),

 

I store image url and name through Configuration::get(variable name) varible..

 

I think i have wrong here to store array variable on prestashop module development.

 

Can you explain how to reference key value through array on module.php file..

Link to comment
Share on other sites

I think there is a wrong logic at the root of it.

 

Is there a chance you can save those like

 

array(

0 => array(

        'image' => 'this is image 1 url',

        'label' => 'this is the label'

    )

)

 

 

?

Link to comment
Share on other sites

×
×
  • Create New...