@jsonFile - Load JSON Data
The @jsonFile
directive in Ahmed PHP Template Engine allows you to load and parse a JSON file directly within your template.
Syntax
filePath
: The path to the JSON file relative to the project directory.
Description
This directive reads a JSON file and converts it into an associative array.
Allows accessing JSON data directly in the template without additional PHP code.
Useful for handling configuration files, translations, or structured data.
Example
Assuming data.json
contains:
You can use:
Expected Output
Notes
Ensure the JSON file is properly formatted to avoid parsing errors.
Nested JSON properties can be accessed using dot notation (e.g.,
@data.key
).If the file does not exist or contains invalid JSON, an error may occur.
Last updated