已经在类文件中用php准备了字符串修改。现在在输出字符串时在smarty模板(tpl)文件中,我得到了错误的文本格式。该项目使用smarty 3.1-DEV和php 5.6。
我有这个php代码,并在php类文件中分配了变量:
$pattern = '/' . implode('|', $allergens_searchnames) . '/iu';
echo preg_replace_callback($pattern, function ($m) {
return mb_strtoupper($m[0]); }, $prodIngredients);
}
$this->assign("articleIngredients", $prodIngredients);
直接在类文件中使用“ echo”输出,我在前端获得了所需的格式:“祖塔滕:MARILLEN(75%),Zucker,Zitronensaft,Geliermittel:PEKTINe(aus Apfel)“
智能输出的实现是错误的:“祖塔滕:Marillen(75%),Zucker,Zitronensaft,Geliermittel:Pektine(aus Apfel)“
就像我在tpl文件中实现的一样:
<span class="pull-right">
{if isset($articleIngredients)}
<p>{$articleIngredients|unescape:'html'}</p>
{/if}
</span>
由于我对项目不了解太多,而且很聪明,所以几乎不可能为我解决此问题。任何帮助表示赞赏。
我认为这2个中的一个可能会对您有所帮助。尝试使用unescape:'htmlall'或尝试将文本打印为文字文本
<span class="pull-right">
{if isset($articleIngredients)}
<p>{$articleIngredients}|unescape:'htmlall'}</p>
{/if}
来源:https://www.smarty.net/docs/en/language.modifier.unescape.tpl
{literal} {/ literal}标记中的所有内容均不会解释,而是按原样显示。
<span class="pull-right">
{if isset($articleIngredients)}
<p>{literal}{$articleIngredients}{/literal}</p>
{/if}
</span>
来源:https://www.smarty.net/docs/en/language.function.literal.tpl
我找到了直接在模板上实现它的解决方案:smarty replace multiple values
问题是硬编码所有不同的可能性以替换成两个数组。也许我可以为此找到另一个解决方案。
您首次尝试使用unescape:'htmlall'仅将首字母大写的字符串排除在外。尽管需要用大写的特定单词,但仍需要精确的字符串操作。