简体   繁体   English

聪明猫逃脱html

[英]Smarty cat escapes html

I have simple code: 我有简单的代码:

{html_checkboxes values=$user_data['names']['id'] output = $user_data['names']['user_name']|cat:' | Status: '|cat:$user_data['names']['status'] escape=false}

In array $user_data['names']['status'] is stored user statuses like <span style="color: red">User</span> , so i need to display it like Username | 在数组$user_data['names']['status']中存储了用户状态,例如<span style="color: red">User</span> ,因此我需要将其显示为Username | Status: User (user in red), but smarty cut it off. 状态:用户 (用户为红色),但是巧妙地将其切断。 Without cat, it there just 1 variable it is all ok. 如果没有cat,它只有1个变量就可以了。

I also tested {user_data['names']['status']} , "lol"|cat:$user_data['names']['status'] and $user_data['names']['user_name']|cat:' | Status: '|cat:$user_data['names']['status'] 我还测试了{user_data['names']['status']}"lol"|cat:$user_data['names']['status']$user_data['names']['user_name']|cat:' | Status: '|cat:$user_data['names']['status'] $user_data['names']['user_name']|cat:' | Status: '|cat:$user_data['names']['status'] - it works ok. $user_data['names']['user_name']|cat:' | Status: '|cat:$user_data['names']['status'] -正常。 Where is the problem? 问题出在哪儿?

Depending on the version (Smarty2 / Smarty3) you might need to one of the following: 根据版本(Smarty2 / Smarty3),您可能需要以下之一:

{html_checkboxes values=$user_data.names.id output={$user_data.names.user_name|cat:' | Status: '|cat:$user_data.names.status} escape=false}

assign your value to a variable to dumb things down: 将您的值分配给变量以使事情变得愚蠢:

{assign var="foo" value=$user_data.names.user_name|cat:' | Status: '|cat:$user_data.names.status}
{html_checkboxes values=$user_data.names.id output=$foo escape=false}

or use {capture} for more complex things (removing the need for the cat modifier): 或使用{capture}处理更复杂的事情(无需使用cat修饰符):

{capture assign="foo"}{$user_data.names.user_name|cat:' | Status: '|cat:$user_data.names.status}{/capture}
{html_checkboxes values=$user_data.names.id output=$foo escape=false}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM