HeaderTmpl::setData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
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