Php 使用smarty复制包含3个级别的选项组

Php 使用smarty复制包含3个级别的选项组,php,smarty,Php,Smarty,在最近的一个项目中,我发现他们正在使用smarty,客户机需要一个包含3个级别的选项组。我从来没有用过smarty,我发现这个特殊的案例有点难以从头开始 我需要做下一步,但使用smarty: <select> <optgroup label="Level One"></optgroup> <optgroup label="Level Two" style="padding-left:15px"></optgroup&g

在最近的一个项目中,我发现他们正在使用smarty,客户机需要一个包含3个级别的选项组。我从来没有用过smarty,我发现这个特殊的案例有点难以从头开始

我需要做下一步,但使用smarty:

<select>
    <optgroup label="Level One"></optgroup>
        <optgroup label="Level Two" style="padding-left:15px"></optgroup>
            <option style="padding-left:30px"> A.B.1 </option>    
        <optgroup label="Level Two" style="padding-left:15px"></optgroup>
            <option style="padding-left:30px"> A.B.2 </option>
    <optgroup label="Level One"></optgroup>
        <optgroup label="Level Two" style="padding-left:15px"></optgroup>
            <option style="padding-left:30px"> A.B.1 </option>    
        <optgroup label="Level Two" style="padding-left:15px"></optgroup>
        <option style="padding-left:30px"> A.B.2 </option>    
</select>
这实际上只给了我两个级别

更新2

看一看

编辑 Smarty3模板

{$options = [
  "Level1 - 1st" => [
    "Level2 - 1st" => "Level2 - 1st",
    "Level2 - 2nd" => ["Hello", "World"]
  ],
  "Level1 - 2nd" => [
    "Level2 - 3rd" => "Level2 - 3rd",
    "Level2 - 4th" => ["Hello" => "Hello", "other", "World"]
  ]
]}

<select>{html_options options=$options}</select>
{$options=[
“1级-1级”=>[
“二级-一级”=>“二级-一级”,
“2级-2级”=>[“你好”,“世界”]
],
“1级-2级”=>[
“二级-三级”=>“二级-三级”,
“二级-四级”=>[“你好”=>“你好”、“其他”、“世界”]
]
]}
{html_options options=$options}
生成以下HTML(手动缩进)


二级-一级
你好
世界
二级至三级
你好
其他
世界
这和人们所期望的很像。但在Firefox7中查看这一点,我看到正确嵌套的组显示在同一级别上:


不错的提示,但我不能用它达到3级。我用我的代码更新了。提前谢谢你!我刚刚更新了帖子。{html_options}确实呈现嵌套的s-这是您的浏览器没有按预期显示它们。我已经更新了第一个呈现的代码示例,然后是您发布的代码示例。有些东西失败了;({html_options}不会接受任何类似的参数,不。您必须使用自己构建它。
{$options = [
  "Level1 - 1st" => [
    "Level2 - 1st" => "Level2 - 1st",
    "Level2 - 2nd" => ["Hello", "World"]
  ],
  "Level1 - 2nd" => [
    "Level2 - 3rd" => "Level2 - 3rd",
    "Level2 - 4th" => ["Hello" => "Hello", "other", "World"]
  ]
]}

<select>{html_options options=$options}</select>
<select>
  <optgroup label="Level1 - 1st">
    <option value="Level2 - 1st">Level2 - 1st</option>
    <optgroup label="Level2 - 2nd">
      <option value="0">Hello</option>
      <option value="1">World</option>
    </optgroup>
  </optgroup>
  <optgroup label="Level1 - 2nd">
    <option value="Level2 - 3rd">Level2 - 3rd</option>
    <optgroup label="Level2 - 4th">
      <option value="Hello">Hello</option>
      <option value="0">other</option>
      <option value="1">World</option>
    </optgroup>
  </optgroup>
</select>