-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateClient.php
More file actions
208 lines (198 loc) · 4.81 KB
/
Copy pathTemplateClient.php
File metadata and controls
208 lines (198 loc) · 4.81 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php declare(strict_types=1);
namespace Computator\FrameworkUtils\PHPTemplate\UserApi;
/**
* Template engine methods available in templates.
*/
interface TemplateClient {
/**
* Output a block defined in a child template.
*
* This method is used to output a block that a child template has previously
* defined using `self::block()`. The return value of this method can be
* used to decide whether to render any fallback content.
*
* This method is only valid in a template that has been set as a parent
* from a child via `self::inherit()`.
*
* # Examples
*
* ## Normal
*
* ```php
* <? self::block('block_name'): ?>
* ```
*
* ## Fallback
*
* ```php
* <? if(!self::block('block_name')): ?>
* Fallback content
* <? endif ?>
* ```
*
* @return bool whether or not the block was found and output
*/
public function block(string $block_name): bool;
/**
* Start defining a template block.
*
* Blocks defined with this method can be output in the parent template
* using `self::block()`.
*
* This method is only valid in a child template that has set a
* parent with `self::inherit()`.
*
* # Example
*
* ```php
* <? self::define('block_name') ?>
* Block content
* <? self::define_end() ?>
* ```
*/
public function define(string $block_name): void;
/**
* End the current template block being defined.
*
* This method is used to mark the end of a block started with `self::define()`.
*
* This method is only valid in a child template that has set a
* parent with `self::inherit()`.
*
* # Example
*
* ```php
* <? self::define('block_name') ?>
* Block content
* <? self::define_end() ?>
* ```
*/
public function define_end(): void;
/**
* Set a parent template to render this template with.
*
* This method can not be called more than once per template.
*
* # Example
*
* ## `child.php`
*
* ```php
* <? self::inherit('parent.php') ?>
*
* <? self::define('block_one') ?>
* Block content
* <? self::define_end() ?>
* ```
*
* ## `parent.php`
*
* ```php
* <div class="content">
* <? self::block('block_one') ?>
* </div>
* ```
*/
public function inherit(string $parent_template): void;
/**
* Create an insertion point for future content.
*
* This method is used to create an insertion point that can then be appended
* to from elsewhere in the rendering process. The insertion point is stored
* under the provided name which must be unique across all referenced templates.
*
* Note that content can be appended to an insertion point before it is created.
*
* # Example
*
* ```php
* <? self::insert_set('insert_name'): ?>
* ```
*/
public function insert_set(string $insert_name): void;
/**
* Start appending to an insertion point.
*
* Content blocks defined with this method will be appended to an insertion
* point created elsewhere using `self::insert_set()`.
*
* # Example
*
* ```php
* <? self::insert('insert_name'): ?>
* Content to be appended
* <? self::insert_end() ?>
* ```
*/
public function insert(string $insert_name): void;
/**
* Stop appending to the current insertion point.
*
* This method is used to mark the end of a content block defined with
* `self::insert()` that will be appended to the selected insertion point.
*
* # Example
*
* ```php
* <? self::insert('insert_name'): ?>
* Content to be appended
* <? self::insert_end() ?>
* ```
*/
public function insert_end(): void;
/**
* Output non-block content from a child template.
*
* This method is used to output all content displayed in a child
* template outside of defined blocks.
*
* This method is only valid in a template that has been set as a parent
* from a child via `self::inherit()`.
*
* # Example
*
* ## `child.php`
*
* ```php
* <? self::inherit('parent.php') ?>
*
* <p>Content outside block</p>
* ```
*
* ## `parent.php`
*
* ```php
* <div class="content">
* <? self::primary() ?>
* </div>
* ```
*/
public function primary(): void;
/**
* Retrieve a reference to another template.
*
* This method is used to load another template to render. This returns a
* reference to the template rather than immediately rendering it, so the
* template can be used immediately or saved in a variable for later use.
*
* This method returns a reference to the template as an object that
* implements [UserApi\ResolvedTemplateClient](ResolvedTemplateClient.php).
*
* # Example
*
* ## `main.php`
*
* ```php
* <? self::tpl('child.php')() ?>
* ```
*
* ## `child.php`
*
* ```php
* <p>Child content</p>
* ```
*
* @return ResolvedTemplateClient Template reference as [UserApi\ResolvedTemplateClient](ResolvedTemplateClient.php)
*/
public function tpl(string $template): ResolvedTemplateClient;
}