forked from wanze/TemplateEngineFactory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateEngineProcesswire.module
More file actions
117 lines (97 loc) · 2.43 KB
/
TemplateEngineProcesswire.module
File metadata and controls
117 lines (97 loc) · 2.43 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
require_once('TemplateEngine.php');
/**
* TemplateEngineProcesswire
*
* @author Stefan Wanzenried <stefan.wanzenried@gmail.com>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License, version 2
* @version 1.0.1
*
* ProcessWire 2.x
* Copyright (C) 2014 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://processwire.com
*/
class TemplateEngineProcesswire extends TemplateEngine implements Module, ConfigurableModule
{
/**
* @var TemplateFile
*/
protected $template;
/**
* @param string $filename
*/
public function __construct($filename = '')
{
parent::__construct($filename);
}
/**
* Initialize module
*/
public function initEngine()
{
$this->template = new TemplateFile($this->getTemplatesPath() . $this->getFilename());
}
/**
* @return array
*/
public static function getDefaultConfig()
{
$config = parent::getDefaultConfig();
return array_merge($config, array(
'template_files_suffix' => 'php',
));
}
/**
* Set a key/value pair to the template
*
* @param $key
* @param $value
*/
public function set($key, $value)
{
$this->template->set($key, $value);
}
/**
* Render markup from template file
*
* @return mixed
*/
public function render()
{
return $this->template->render();
}
/**
* Per interface Module, ConfigurableModule
*
*/
/**
* @return array
*/
public static function getModuleInfo()
{
return array(
'title' => 'Template Engine ProcessWire',
'version' => 101,
'author' => 'Stefan Wanzenried',
'summary' => 'ProcessWire templates for the TemplateEngineFactory',
'href' => '',
'singular' => false,
'autoload' => false,
'requires' => array('TemplateEngineFactory'),
);
}
/**
* Return an InputfieldWrapper of Inputfields used to configure the class
*
* @param array $data Array of config values indexed by field name
* @return InputfieldWrapper
*/
public static function getModuleConfigInputfields(array $data)
{
$data = array_merge(self::getDefaultConfig(), $data);
$wrapper = parent::getModuleConfigInputfields($data);
return $wrapper;
}
}