我制作了从数组创建表单的模板。它动态选择名称并从上次获取的值中选择。但我不能像普通的 php 那样写 eval
eval('$value = "\$smarty.get.'.$feature.name.'";');
在我的模板中
<div id="BMTProductsSearch" class="block">
<h4>Search</h4>
<form id="FBMTProductsSearch" action="{$link->getPageLink('search.php', true)}" method="get">
<ul>
{foreach from=$features item=feature}
<li>
<label for="{$feature.name}">{$feature.name}</label>
<select name="{$feature.name}">
<option value="">-- {$feature.name} --</option>
{foreach from=$feature.options item=option}
{eval var='$value = "\$smarty.get.'.$feature.name.'";' assign="value"}
<option value="'{$option.value}'">{$option.value} {$value}</option>
{/foreach}
</select>
</li>
{/foreach}
<li>
<label for="search_query_block">{l s='product name' mod='BMTProductsSearch'}</label>
<input class="search_query" type="text" id="search_query_block" name="search_query" value="{if isset($smarty.get.search_query)}{$smarty.get.search_query|htmlentities:$ENT_QUOTES:'utf-8'|stripslashes}{/if}">
</li>
<li>
<input type="hidden" name="orderby" value="position">
<input type="hidden" name="orderway" value="desc">
<input type="submit" id="search_button" class="button_mini" value="{l s='go' mod='BMTProductsSearch'}">
</li>
</ul>
</form>
</div>