If Statement

The If Statement in Ahmed Template Engine for INEX SPA allows you to conditionally render content based on logical expressions, similar to traditional PHP if-statements but in a cleaner, template-friendly syntax.

Syntax

@if(condition)
    <!-- Code to execute if the condition is true -->
@endif

Example:

@if($user)
    <p>Welcome, {{$user['name']}}!</p>
@endif

This will display the welcome message only if the $user variable is set.

Else Condition

To execute alternative code when the condition is false, use @else:

@if($isLoggedIn)
    <p>You are logged in.</p>
@else
    <p>Please log in.</p>
@endif

Else If (@elseif)

For multiple conditions, use @elseif:

Nested If Statements

You can nest @if statements for more complex logic:

Using Logical Operators

You can use logical operators in conditions:

Conclusion

The If Statement in Ahmed Template Engine provides a simple and efficient way to control content visibility based on conditions, making templates more dynamic and user-friendly.

Last updated