|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
RomanTarasov Smarty Rookie
Joined: 21 Nov 2014 Posts: 6
|
Posted: Fri Nov 21, 2014 1:34 pm Post subject: Pass multi level array to pulgin from within smarty template |
|
|
I created a plugin and need to be cable to pass multi dementional array to it. However having errors thrown at me when i use either [] or => inside smarty template. Is there way around?
This works
Code: | {html_myfunction loop=$mydata
settings=array(one,two,thee)
objects=array(apple,tree,car)
} |
This does not
Code: | {html_myfunction loop=$mydata
settings=array(
one => apple,
two => tree,
thee => car)
} |
I have to pass 3 long arrays with custom settings that i need to pass to custom function, i'd ideally need to use multi-dimensional array for that.
Another very needed thing is to post sub array like
Code: | {html_myfunction loop=$mydata[5]} |
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Nov 21, 2014 5:34 pm Post subject: Re: Pass multi level array to pulgin from within smarty temp |
|
|
RomanTarasov wrote: | multi dementional array
Code: | {html_myfunction loop=$mydata
settings=array(
one => apple,
two => tree,
thee => car)
} |
|
That's hardly a multidimensional array.
Also, you're doing it wrong.
Prepare data in your code. Template should only make a presentation from it. |
|
Back to top |
|
RomanTarasov Smarty Rookie
Joined: 21 Nov 2014 Posts: 6
|
Posted: Sat Nov 22, 2014 8:39 am Post subject: Re: Pass multi level array to pulgin from within smarty temp |
|
|
AnrDaemon wrote: | That's hardly a multidimensional array. |
You got me on the terms, i dont know them.
Point was that smarty don't let you use assignment operator => so making associative and/or associative multidimensional array does not work and i need it to work.
AnrDaemon wrote: | Prepare data in your code. Template should only make a presentation from it. |
Is it incorrect if i:
1. make SQL query in PHP
2. processed response in PHP to be an array like this
Code: | array(
0 => array(
0 => "value1"
"sql_column1_name" => "value1"
1 => "value2"
"sql_column2_name" => "value2"
2 => "value3"
"sql_column3_name" => "value3"
)
1 => array(
0 => "value4"
"sql_column1_name" => "value4"
1 => "value5"
"sql_column2_name" => "value5"
2 => "value6"
"sql_column3_name" => "value6"
)
)
|
3. assign array to template variable
4. loop trough array it with {section} to make html table? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Nov 23, 2014 7:06 pm Post subject: |
|
|
Oh, so, you're doing it even more wrong, than I though.
Why you have duplicated data in your array to begin with? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|