user3344670
user3344670

Reputation: 7

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".

Upvotes: 0

Views: 225

Answers (2)

Akshay Kalose
Akshay Kalose

Reputation: 777

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

Upvotes: 1

ops
ops

Reputation: 2049

Try this code:

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

Upvotes: 0

Related Questions