SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to check if a variable is set in smarty template?

    is there a function that I can use inside smarty template if any value is assigned to a template variable? something like:

    {if $variable === null }

    {/if}

  2. #2
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LAMP View Post
    is there a function that I can use inside smarty template if any value is assigned to a template variable? something like:

    {if $variable === null }

    {/if}


    manual: http://www.smarty.net/manual/en/lang...unction.if.php

    Down in the examples you can see the following:

    Code:
    {if isset($name) && $name == 'Blog'}
         {* do something *}
    {elseif $name == $foo}
        {* do something *}
    {/if}
    From that code I deduct that you need to to this:

    Code:
    {if !isset($variable)}
    
    {/if}
    PS: I have never used Smarty, need to learn new syntax for what you can do with PHP
    edit
    Reason why Smarty is too bulky http://www.sitepoint.com/article/bey...mplate-engine/
    (if you are interested)
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code you provided worked. Thanks.

    Actually, I know that you can also use native PHP templating instead of Smarty. It's matter of taste and convinience. I find myself more productive with smarty.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •