\Greg\View\Renderer is an instance of a template. Could be accessed via $this variable in the template.
Example:
<header>
<?php echo $this->getSection("header")?>
</header>
<section class="content">
<?php echo $this->content()?>
</section>
<footer>
<?php echo $this->getSection("footer")?>
</footer>Initialize the renderer.
__construct(Viewer $viewer, string $file, array $params = [])$viewer - Viewer;
$file - Template file;
$params - Template parameters.
Example:
$viewer = new \Greg\View\Viewer(__DIR__ . '/views');
$renderer = new \Greg\View\ViewRenderer($viewer, __DIR__ . '/welcome.php', [
'name' => 'Greg',
]);- render - Render a template file with current parameters;
- renderIfExists - Render a template file with current parameters if template exists;
- renderString - Render a template string with current parameters;
- renderStringIfExists - Render a template string with current parameters if template exists;
- partial - Render a template file with new parameters;
- partialIfExists - Render a template file with new parameters if template exists;
- partialString - Render a template string with new parameters;
- partialStringIfExists - Render a template string with new parameters if template exists;
- each - Render a template file with current parameters for each value;
- eachIfExists - Render a template file with current parameters for each value if template exists;
- eachString - Render a template string with current parameters for each value;
- eachStringIfExists - Render a template string with current parameters for each value if template exists;
- extend - Extend template with another template file;
- extendString - Extend template with another template string;
- content - Get content;
- section - Start or add a section;
- parent - Get parent section;
- endSection - End and register current section;
- show - End and get current section;
- getSection - Get a section;
- push - Start a pusher or push contents in the stack;
- endPush - End current pusher and add it to the stack;
- stack - Get from the stack;
- format - Execute a directive registered in the Viewer;
- viewer - Get Viewer;
- params - Get parameters;
- file - Get file;
- extended - Get extended template file;
- setContent - Set content;
- setSections - Set sections;
- getSections - Get sections;
- hasSection - Determine if a section exists;
- setStacks - Set stacks;
- getStacks - Get stacks;
- hasStack - Determine if a stack exists;
- __call - Execute a directive registered in the Viewer.
Render a template file with current parameters.
render(string $name, array $params = []): string$name - Template file;
$params - Template custom parameters.
Example:
<?php echo $this->render('header', [
'title' => 'I am a header!',
])?>Render a template file with current parameters if template exists. See render method.
Render a template string with current parameters.
renderString(string $id, string $string, array $params = []): string$id - Template unique id. It should has the compiler extension;
$string - Template string;
$params - Template custom parameters.
Example:
<?php echo $this->renderString('header.php', '<header><?php echo $title?></header>', [
'title' => 'I am a header!',
])?>Render a template string with current parameters if its compiler exists. See renderString method.
Render a template file with new parameters.
partial(string $name, array $params = []): string$name - Template file;
$params - Template parameters.
Render a template file with new parameters if template exists. See partial method.
Render a template string with new parameters.
partialString(string $id, string $string, array $params = []): string$id - Template unique id. It should has the compiler extension;
$string - Template string;
$params - Template custom parameters.
Render a template string with new parameters if its compiler exists. See partialString method.
Render a template file with current parameters for each value.
each(string $name, array $values, array $params = [], string $valueKeyName = null, string $emptyName = null): string$name - Template file;
$values - Values;
$params - Template custom parameters;
$valueKeyName - The key name of the current value;
$emptyName - If no values, will render this template file.
Render a template file with current parameters for each value if template exists. See each method.
Render a template string with current parameters for each value.
eachString(string $id, string $string, array $values, array $params = [], string $valueKeyName = null, string $emptyId = null, string $emptyString = null): string$id - Template unique id. It should has the compiler extension;
$string - Template string;
$values - Values;
$params - Template custom parameters;
$valueKeyName - The key name of the current value;
$emptyId - Template unique id. Will use it if no values found;
$emptyString - Template string. Will use it if no values found.
Render a template string with current parameters for each value if template exists. See eachString method.
Extend template with another template file.
extend(string $name): $this$name - Template file.
Extend template with another template string.
extend(string $id, string $string): $this$id - Template unique id. It should has the compiler extension;
$string - Template string.
Get content.
content(): stringStart or add a section.
section(string $name, string $content = null): $this$name - Section name;
$content - Section content.
Get parent section.
parent(): $thisEnd and register current section.
endSection(): $thisFinish and get current section content.
show(): stringGet a section.
getSection(string $name, string $else = null): string$name - Section name;
$else - If the section does not exists, return this content.
Start a pusher or push contents in the stack.
push(string $name, string $content = null): $this$name - Stack name;
$content - Stack content.
End current pusher and add it to the stack.
endPush(): $thisGet from the stack.
stack(string $name, string $else = null): string$name - Stack name;
$else - If the stack doesn't exists, return this content.
Execute a directive registered in the Viewer.
format(string $name, mixed ...$args): mixed$name - Directive name;
...$args - Directive arguments.
Get Viewer.
viewer(): \Greg\View\ViewerGet parameters.
params(): arrayGet file.
file(): stringGet extended template file.
extended(): stringSet content.
setContent(string $content): $this$content - Registered content.
Set sections.
setSections(array $sections): $this$sections - Sections.
Get sections.
getSections(): arrayDetermine if a section exists.
hasSection(string $name): boolean$name - Section name.
Set stacks.
setStacks(array $stacks): $this$stacks - Stacks.
Get stacks.
getStacks(): arrayDetermine if a stack exists.
hasStack(string $name): boolean$name - Stack name.