using smarty to generate selection list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • glin@tollnz.co.nz

    #1

    using smarty to generate selection list

    Hi there,

    does anyone know how to use smarty to generate a selection list without
    PHP assigning a array?
    eg. a list for selection minutes, but without php to assign a 1~60
    array into smarty.

    Thanks in advance.

  • glin@tollnz.co.nz

    #2
    Re: using smarty to generate selection list

    also, I want to put in id inside the <select> tag as well.

    Comment

    • Jan Pieter Kunst

      #3
      Re: using smarty to generate selection list

      glin@tollnz.co. nz wrote:
      [color=blue]
      > does anyone know how to use smarty to generate a selection list without
      > PHP assigning a array?
      > eg. a list for selection minutes, but without php to assign a 1~60
      > array into smarty.[/color]
      [color=blue]
      > also, I want to put in id inside the <select> tag as well.[/color]

      Can't help you with the first question, I think you need to use a PHP
      array (but it can be one line, like: $seconds = range(1..60) or
      something. Look up the range() function for the exact syntax.

      You can put your own attributes in Smarty tags simply like this:

      {html_options name="name" options=$option s id="id"}

      JP

      --
      Sorry, <devnull@cauce. org> is a spam trap.
      Real e-mail address unavailable. 5000+ spams per month.

      Comment

      • Ian.H

        #4
        Re: using smarty to generate selection list

        On 3 Apr 2005 19:36:23 -0700, "glin@tollnz.co .nz" <glin@tollnz.co .nz>
        wrote:
        [color=blue]
        >Hi there,
        >
        >does anyone know how to use smarty to generate a selection list without
        >PHP assigning a array?
        >eg. a list for selection minutes, but without php to assign a 1~60
        >array into smarty.
        >
        >Thanks in advance.[/color]


        <select name="mins" id="mins">
        {section name=mins loop=60}
        <option value="{$smarty .section.mins.i teration}">
        {$smarty.sectio n.mins.iteratio n}
        </option>
        {/section}
        </select>



        HTH =)



        Regards,

        Ian


        --
        Ian.H
        digiServ Network
        London, UK

        Comment

        • glin@tollnz.co.nz

          #5
          Re: using smarty to generate selection list

          thanks guys, here is a more challenging question
          regarding on Ian's solution,

          how do I add 0 infront of the numbers that is less than 10?
          so I will have 01, 02, ~ 10

          thanks in advance

          Comment

          • Ian.H

            #6
            Re: using smarty to generate selection list

            On 5 Apr 2005 19:47:04 -0700, "glin@tollnz.co .nz" <glin@tollnz.co .nz>
            wrote:
            [color=blue]
            >thanks guys, here is a more challenging question
            >regarding on Ian's solution,
            >
            >how do I add 0 infront of the numbers that is less than 10?
            >so I will have 01, 02, ~ 10
            >
            >thanks in advance[/color]


            Use the string_format modifier:


            <http://smarty.php.net/manual/en/language.modifi er.string.forma t.php>


            {section name=foo loop=10}
            <option name="{$smarty. section.foo.ite ration}">
            {$smarty.sectio n.foo.iteration |string_format: "%02d"}
            </option>
            {/section}



            Regards,

            Ian


            --
            Ian.H
            digiServ Network
            London, UK

            Comment

            Working...