Jump to content
xezus

[solved] How to add a value to smarty array?

Recommended Posts

Hi,

I am having a problem with adding values to my new array which I created in my new module.

 

 

public function install()
{
return (parent::install()
......
&& Configuration::updateValue('my_array', array())
.....
}

 

 

Please could somebody tell me how could I add a new value to this array?

I would be glad for any answer.

Edited by vekia (see edit history)

Share this post


Link to post
Share on other sites

hello

 

in the topic title you're talking about smarty, but as i can see in the code that you pasted, you don't use smarty.

So my questions is, what you exactly expect?

Share this post


Link to post
Share on other sites

I am sorry I am new in prestashop but I would like to create a array in my modul and dynamically add values into it and then use this array in my theme like normal smarty array (like $css_files for example)

 

And from what I understand until know is that I have to create php array like this and then use this

 

 

public function hookDisplayHeader($params) {

 

$this->context->smarty->assign(

array( ...'name' => my created array..... )

);

}

 

 

to enable me to use the array in my theme.

Share this post


Link to post
Share on other sites

that's right, so you've got solution ;)

 

with code that you pasted you can use {$name} variable in your theme - this is the array that you created

Share this post


Link to post
Share on other sites
$array= array('variable1'=>"value", 'variable2'=>"second value", 'variable3' => "last example");

Share this post


Link to post
Share on other sites

sorry for so many questions but how could I do this after that. When the array is already created and I just need to add another value into the array.

  • Like 1

Share this post


Link to post
Share on other sites

$array=array('variable1'=>"value", 'variable2'=>"value2");
$array['new_value']="my new variable";

 

effect:

 

Array
(
   [variable1] => value
   [variable2] => value2
   [new_value] => my new variable
)

  • Like 1

Share this post


Link to post
Share on other sites

you're welcome

 

it works so i can mark this thread as solved

 

if you've got any questions related to arrays and smarty variables - feel free to continue discussion here

 

regards

Share this post


Link to post
Share on other sites

if in php you use code like:

$smarty->assign(array('variable1'=>'value1', 'variable2' => 'value2'));

to access these variables in tpl file use:

 

{$variable1} - it will display "value1"

{$variable2} - it will display "value2"

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More