简体   繁体   中英

Using if/else in the smarty template system?

I'm new to using the smarty template system and was hoping someone could help me with this.

If {$clientsdetails.customfields1} is null OR blank, I want it to show the message "not working". If there's anything entered in that field, I want it to show the message "currently working".

Try this:

{if empty($clientsdetails.customfields1)}
    <p>Not Working</p>
{else}
    <p>Currently Working</p>
{/if}

This will check if $clientsdetails.customfields1 is not set or if it equals false.

In PHP all of these are considered to be false:

  • false
  • 0
  • 0.0
  • ""
  • "0"
  • null

If it is not set or == false, it will show 'Not Working' otherwise 'Currently Working'

Documentation for more Information: http://www.smarty.net/docs/en/language.function.if.tpl

Try this code:

{if $clientsdetails.customfields1==""}
    not working
{else}
    currently working
{/if}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM