|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_templates\example; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_templates\ATemplate; |
|
7
|
|
|
use kalanis\kw_templates\Template\TFile; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class HeaderTmpl extends ATemplate |
|
11
|
|
|
{ |
|
12
|
|
|
use TFile; |
|
13
|
|
|
|
|
14
|
|
|
protected function templatePath(): string |
|
15
|
|
|
{ |
|
16
|
|
|
// get path to file - shared between languages |
|
17
|
|
|
return realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'shared-example', 'header.html'])); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
protected function fillInputs(): void |
|
21
|
|
|
{ |
|
22
|
|
|
// set which keys will be looked for and what default values they will need |
|
23
|
|
|
// usually it's good thing to set default values as some main language |
|
24
|
|
|
$this->addInput('{TITLE}', 'Example for %s', 'Example for loading'); |
|
25
|
|
|
$this->addInput('{ENCODING}', 'utf-8'); |
|
26
|
|
|
$this->addInput('{CONTENT}', 'HTML page - example of filling with these templates.'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function setData(): void |
|
30
|
|
|
{ |
|
31
|
|
|
// this is example how to update values |
|
32
|
|
|
$this->getItem('{ENCODING}')->setValue('win-1250'); |
|
33
|
|
|
// another way is re-set them |
|
34
|
|
|
$this->updateItem('{CONTENT}', 'HTML - updated after load, not before'); |
|
35
|
|
|
// last one is to change values depending on state of code |
|
36
|
|
|
$input = $this->getItem('{ENCODING}'); |
|
37
|
|
|
$input->setValue(sprintf($input->getDefault(), 'running')); |
|
38
|
|
|
$input->updateValue('trash'); |
|
39
|
|
|
|
|
40
|
|
|
// now just call HeaderTmpl->render() and dump output where you wish |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|