简体   繁体   中英

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 | Status: User (user in red), but smarty cut it off. Without cat, it there just 1 variable it is all ok.

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']['user_name']|cat:' | Status: '|cat:$user_data['names']['status'] - it works ok. Where is the problem?

Depending on the version (Smarty2 / Smarty3) you might need to one of the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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