Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Pass multi level array to pulgin from within smarty template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
RomanTarasov
Smarty Rookie


Joined: 21 Nov 2014
Posts: 6

PostPosted: Fri Nov 21, 2014 1:34 pm    Post subject: Pass multi level array to pulgin from within smarty template Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Nov 21, 2014 5:34 pm    Post subject: Re: Pass multi level array to pulgin from within smarty temp Reply with quote

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
View user's profile Send private message
RomanTarasov
Smarty Rookie


Joined: 21 Nov 2014
Posts: 6

PostPosted: Sat Nov 22, 2014 8:39 am    Post subject: Re: Pass multi level array to pulgin from within smarty temp Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Nov 23, 2014 7:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP