@set - Assigning Variables
The @set directive in Ahmed PHP Template Engine allows you to assign values to variables within a template. This is useful for defining dynamic content inside your templates without modifying the controller logic.
Syntax
@set(variable, value)variableis the name of the variable you want to assign.valueis the value to be assigned to the variable.
Example
@set(title, 'Welcome to My Website')
<h1>{{ title }}</h1>Output
<h1>Welcome to My Website</h1>Notes
The variable assigned using
@setcan be accessed anywhere in the template using{{ variable }}.Variables set using
@setpersist only within the template scope where they are defined.You can use
@setto store values for loops, conditions, or other dynamic content.
Last updated