sFire PHP Framework

Template engine: If, else and elseif statements

Using if and else statements is required to make your view more dynamic.

In this section we will handle:

  • If, elseif and else
  • Isset and empty methods

If, elseif and else

You may construct if statements using the @if, @elseif, @else, and @endif built-in functions. These built-in functions function identically to their PHP counterparts.

@if (count($records) === 1)
    I have one record!
@elseif (count($records) > 1)
    I have multiple records!
@else
    I don't have any records!
@endif

Isset and empty methods

Instead of writing an if statement which will check if something is defined or empty, you can use the short-hand methods @isset, @empty, @notisset and @notempty as convenient shortcuts:

Isset
@isset($foo)
    // $foo is defined and is not null
@endisset
Not isset
@notisset($foo)
    // $foo is not defined
@endnotisset
Empty
@empty($foo)
    // $foo is "empty"
@endempty
Not empty
@notempty($foo)
    // $foo is not "empty"
@endnotempty