@php - Executing Raw PHP Code
The @php directive in Ahmed PHP Template Engine allows you to write raw PHP code within your templates. This is useful for executing logic that cannot be easily expressed using template directives.
Syntax
@php
// PHP code here
@endphpAny PHP code written inside
@phpand@endphpwill be executed as standard PHP.
Example
@php
$date = date('Y-m-d');
@endphp
<p>Today's date is {{ date }}</p>Output
<p>Today's date is 2025-03-30</p>Notes
Use
@phponly when necessary; template logic should ideally remain clean and minimal.Inside
@php, you can define variables, perform calculations, and execute any PHP code.You can access PHP variables set within
@phpusing{{ variable }}in the template.
Previous@empty - Checking If a Variable Is EmptyNext@unless - Conditional Rendering for False Values
Last updated