How to check complex state in Smarty (PHP)

I need to display a section or another in a smarty template. My condition is simple: if the smarty value starts with a string, I have to display one section, otherwise another smarty section should be displayed. I can only change tpl files.

    {php}
    if (substr($url,0,4) != 'http')
    {
    {/php}
                  section 1

    {php}
    }
    else
    {
    {/php}
        section 2   
    {php}
    }
    {/php}

The problem is that I cannot read the varil that was previously assigned using $ smarty-> assign. Basically, I'm looking for a smarty function that can be used to extract a value or if there is a better solution.

+5
source share
1 answer

First, I would clear your code. You don't need php tags, you use smarty:

 {if substr($url,0,4) neq 'http'}

     section 1

 {else}
        section 2   
 {/if}

This is untested, but should be pretty close.

, - , , ​​ , HTTP_HOST, - :

 {assign var='url' value=$smarty.server.HTTP_HOST}

 {if substr($url,0,4) neq 'http'}

     section 1

 {else}
        section 2   
 {/if}
+5

All Articles