-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
52 lines (41 loc) · 1.39 KB
/
example.php
File metadata and controls
52 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require 'vendor/autoload.php';
use ModXengine\View;
use ModXengine\ModXEngine;
use ModXengine\Cache\TemplateCache;
// $environment = TemplateLoader::templatePath('templates');
// $cache = new TemplateCache('cache', 'template', 3600);
// $engine = new ModXEngine($environment, $cache);
// $engine->set('food', 'yam')
// ->set('title', 'testing')
// ->set('user', 'ile,')
// ->with([
// 'test_data' => ['ssssss', 'ssssss'],
// 'array_test' => ['1', 2, 'testng']
// ])->layout("main");
// echo $engine->render('text', 10);
// You Can Make use of The View Class
use ModXengine\Environment\FromArray;
// Initialize environment
$environment = FromArray::templatePath(
['templates/'], // Template directories
__DIR__, // Root path
true // Create directories if missing
);
// Initialize View
$view = new View(
environment: $environment,
cacheDir: __DIR__ . '/cache/',
layoutDir: 'layouts',
componentDir: 'components'
);
// Render template
//The with method is used to set multiple data as array while the set method is used to set single data based on key as the first variable and the value as the second
$output = $view
->set('title', 'testing')
->set('user', 'ile,')
->with([
'test_data' => ['ssssss', 'ssssss'],
'array_test' => ['1', 2, 'testng']
])->layout("main");; // Cache for 1 hour
echo $output->render('text', 200);