1

我在我的项目中使用 Smarty 2。

我有一个 HTML 表格,我在其中打印从 PHP 收到的日期。供您参考,我只是将 smarty 模板中必要的代码部分放在下面:

<td>{$street1}, {$street2}, {$city}, {$state_code}, {$zip_code}</td>

现在在上面的代码中,我想检查变量是否$street2具有某些值。如果变量$street2包含某个值,那么我想在<br>之后添加$street1并打印包含在$street2同一行中的新行中的值<td>

我应该如何在 smarty 中实现这一点?

PHP 代码也是如此,如下所示:

$data['user_address'] = $value['street1']."".$value['street2']."".$value['city']."".$value['state_code']."".$value['zip_code'];

在上面的代码中,我还必须检查$value['street2']并插入断线并插入值。

有人可以帮我吗?

4

1 回答 1

1

1:

<td>{$street1}, {if $street2}<br>{$street2}, {/if}{$city}, {$state_code}, {$zip_code}</td>

2:

$data['user_address'] = $value['street1'].""
    .($value['street2'] ? "\n".$value['street2']."" : '')
    .$value['city']."".$value['state_code']."".$value['zip_code'];
于 2014-11-16T17:14:19.060 回答