Smarty PHP - If 语句,变量在双引号和斜杠中
Smarty PHP - If statement with variable in double quotes with slash
我正在 PHP Smarty 中编写一个 if 语句,但我在语法方面遇到了问题。
$post['user_name'] = Chris
我想要这样,如果 $post['post_type'] == "hiddenshared"
并且 URL URI 等于 "/$profile['user_name']"
在这种情况下 /chris
,则不会显示任何内容。我在将 /
连接到 $profile['user_name']
变量时遇到困难。如何在 $profile['user_name']
变量之前添加 /
,使 $profile['user_name']
显示其中包含的字符串而不是文本 $profile['user_name']
?或者我不应该使用 REQUEST_URI
?
这是我的代码
{if $post['post_type'] == "hiddenshared" && ($smarty.server.REQUEST_URI === "/$profile['user_name']")}
{else}
<!-- post -->
{$smarty.server.REQUEST_URI}
{$profile['user_name']}
{/if}
if 语句将 /$profile['user_name']
读取为 /$profile['user_name']
,而它应该将其读取为 /Chris
。我应该如何解决这个问题?
您可以在双引号字符串中使用大括号分隔符
$smarty.server.REQUEST_URI === "/{$profile['user_name']}"
我正在 PHP Smarty 中编写一个 if 语句,但我在语法方面遇到了问题。
$post['user_name'] = Chris
我想要这样,如果 $post['post_type'] == "hiddenshared"
并且 URL URI 等于 "/$profile['user_name']"
在这种情况下 /chris
,则不会显示任何内容。我在将 /
连接到 $profile['user_name']
变量时遇到困难。如何在 $profile['user_name']
变量之前添加 /
,使 $profile['user_name']
显示其中包含的字符串而不是文本 $profile['user_name']
?或者我不应该使用 REQUEST_URI
?
这是我的代码
{if $post['post_type'] == "hiddenshared" && ($smarty.server.REQUEST_URI === "/$profile['user_name']")}
{else}
<!-- post -->
{$smarty.server.REQUEST_URI}
{$profile['user_name']}
{/if}
if 语句将 /$profile['user_name']
读取为 /$profile['user_name']
,而它应该将其读取为 /Chris
。我应该如何解决这个问题?
您可以在双引号字符串中使用大括号分隔符
$smarty.server.REQUEST_URI === "/{$profile['user_name']}"