Data
To render a view, you certainly need some data. This is handled by the %viewName.data.js
files.
Supported data file types
For now, your can use these formats:
filename.data.json
filename.data.js
filename.data.php
These data files are handled under the hood by the @coffeekraken/s-data-handler-generic package.
Simple example
Assume that you have a view stored here: src/views/hello/hello.blade.php
(it can be a twig as well).
Let's create a new src/views/hello/hello.data.js
file with this content:
This will provide the hello
variable to your view. You can use it like so:
{{ $hello }}
Passing parameters
To access your parameters from your .data.js
file, assume we have this page configuration:
Assume we access our page with this url: /hello/coco/world
In your newly created src/views/hello/hello.data.js
data file, access your parameters like so:
From this point, you can handle pretty much all your data needs.
- Async functions are supported as well
Data files can be in
.data.js
as well as.data.json
and.data.php
formats.