Search code examples
phpstringif-statementconcatenationsmarty

Smarty PHP - If statement with variable in double quotes with slash


I'm writing an if statement in PHP Smarty and I'm having trouble with the syntax.

$post['user_name'] = Chris

I want it so that if $post['post_type'] == "hiddenshared" and the URL URI is equal to "/$profile['user_name']" in this case /chris, then nothing displays. I'm having difficulty concatenating the / to the $profile['user_name'] variable. How do I add the / before the $profile['user_name'] variable in a way that causes the $profile['user_name'] to display the string thats contained within it and not the text $profile['user_name']? Or should I not be using REQUEST_URI?

Here is my code

{if $post['post_type'] == "hiddenshared" && ($smarty.server.REQUEST_URI === "/$profile['user_name']")} 

{else}
    <!-- post -->
    {$smarty.server.REQUEST_URI}
    {$profile['user_name']}
{/if}

The if statement reads /$profile['user_name'] as /$profile['user_name'], when it should be reading it as /Chris. How should I fix this?


Solution

  • You can use the brace delimiters inside of double quoted strings

    $smarty.server.REQUEST_URI === "/{$profile['user_name']}"