使用 smarty 重现 3 个级别的选项组

发布于 2024-12-11 11:52:33 字数 1525 浏览 0 评论 0原文

在最近的一个项目中,我发现他们正在使用 smarty,并且客户需要一个包含 3 个级别的选项组。我从未使用过 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>

我还想知道通知这个聪明人的最佳方式是什么;具有 3 个级别的数组或如何(我使用 PHP)以及如果我有默认选项我必须如何指示它。

先感谢您!

更新:实际使用的代码

$arr['Sport'] = array(6 => 'Golf', 9 => 'Cricket',7 => 'Swim');
$arr['Rest']  = array(3 => 'Sauna',1 => 'Massage', "Test" => array(10 => 'Other', 11 => 'Option'));

$smarty->assign('lookups', $arr);
$smarty->assign('fav', 7);

实际上只给了我 2 个级别。

更新 2

在此处输入图像描述 在此处输入图像描述

In a recent project I have found that they're using smarty and the client needs a option group of 3 levels. I've never used smarty and I find this particular case a little hard to do it from scratch.

I need to do the next but with 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>

I would also want to know what is the best way to inform this smarty; with an array of 3 levels or how (I'm using PHP) and if I have a default option how I've to indicate it.

Thank you in advance!

Update: code actually using

$arr['Sport'] = array(6 => 'Golf', 9 => 'Cricket',7 => 'Swim');
$arr['Rest']  = array(3 => 'Sauna',1 => 'Massage', "Test" => array(10 => 'Other', 11 => 'Option'));

$smarty->assign('lookups', $arr);
$smarty->assign('fav', 7);

This actually is giving me only 2 levels.

Update 2

enter image description here
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把时间冻结 2024-12-18 11:52:33

查看{html_options}

编辑

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>

生成以下 HTML(手动缩进),

<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>

这看起来非常像人们所期望的。但是在 Firefox 7 中查看此内容,我看到正确嵌套的组显示在同一级别上:

opened select

Have a look at {html_options}.

edit

Smarty3 Template

{$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>

generates the following HTML (manually indented)

<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>

Which loooks pretty much like one would expect. But viewing this in Firefox 7, I see the properly nested groups being displayed on the same level:

opened select

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文