Smarty Template Array Question.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    Smarty Template Array Question.

    I have an application that uses an array of values as a "lookup" table and
    smarty as a template engine.

    $lookup['stuff']['a'] = "label";
    $lookup['stuff']['b'] = "label2";
    $lookup['other']['a'] = "label";
    $lookup['other']['b'] = "label2";

    In my application I can easily use this array to find the values I need.

    $data[ $lookup['other']['b'] ];

    I want to assign my lookup value to the template, and have smarty perform
    the matching, but for the life of me I can't get a smarty variable to modify
    itself.

    {$data.$lookup. other.b} doesn't work
    {$data.$lookup[other][b]} also doesn't work.

    I'd also like to use these in functions like

    {html_checkboxe s name="id" options=$data.$ lookup.other.b
    selected=$data. selected }

    I've searched smarty forums, but looking for an instance of "array" in the
    forums it too general, and I can't find anything that points to how to do
    this.

    Any help is appreciated.




  • Daniel Tryba

    #2
    Re: Smarty Template Array Question.

    Brian <ewvea3dgc700 1 .@. sneakemail.com> wrote:[color=blue]
    > $lookup['stuff']['a'] = "label";
    > $lookup['stuff']['b'] = "label2";
    > $lookup['other']['a'] = "label";
    > $lookup['other']['b'] = "label2";
    >
    > I want to assign my lookup value to the template, and have smarty perform
    > the matching, but for the life of me I can't get a smarty variable to modify
    > itself.
    >
    > {$data.$lookup. other.b} doesn't work[/color]

    AFAIK it's not possible, it's ambiguous. You'll have to assign
    $lookup.other.b to a variable in the template.

    BTW IMHO it's bad practice to do these kind of "complicate d" things in a
    template, you should do these things in php before handling a variable
    to smarty, in smarty you shouldn't have to do more than foreach the data
    and print it.

    --

    Daniel Tryba

    Comment

    • Brian

      #3
      Re: Smarty Template Array Question.

      In the event that someone searches for this and gets the same response I
      got, here is the solution I came up with.

      {assign var=temp value=$item.met alabel}
      {$labels.data.$ temp}

      While a bit "wordy", it works.


      "Brian" <ewvea3dgc700 1 .@. sneakemail.com> wrote in message
      news:XUOmc.4530 9$0H1.4262959@a ttbi_s54...[color=blue]
      > I have an application that uses an array of values as a "lookup" table and
      > smarty as a template engine.
      >
      > $lookup['stuff']['a'] = "label";
      > $lookup['stuff']['b'] = "label2";
      > $lookup['other']['a'] = "label";
      > $lookup['other']['b'] = "label2";
      >
      > In my application I can easily use this array to find the values I need.
      >
      > $data[ $lookup['other']['b'] ];
      >
      > I want to assign my lookup value to the template, and have smarty perform
      > the matching, but for the life of me I can't get a smarty variable to[/color]
      modify[color=blue]
      > itself.
      >
      > {$data.$lookup. other.b} doesn't work
      > {$data.$lookup[other][b]} also doesn't work.
      >
      > I'd also like to use these in functions like
      >
      > {html_checkboxe s name="id" options=$data.$ lookup.other.b
      > selected=$data. selected }
      >
      > I've searched smarty forums, but looking for an instance of "array" in the
      > forums it too general, and I can't find anything that points to how to do
      > this.
      >
      > Any help is appreciated.
      >
      >
      >
      >[/color]


      Comment

      Working...