\Greg\View\ViewBladeCompiler
is an extended Blade Compiler, specially for the Viewer Contract.
Extends: \Greg\View\BladeCompiler
.
Implements: \Greg\View\ViewCompilerStrategy
.
Includes Blade Compiler methods.
- addViewDirective - Add a directive that was already registered in the Viewer, but not in the compiler.
Add a directive that was already registered in the Viewer, but not in the compiler.
addViewDirective(string $name): $this
$name
- Directive name;
Example:
$compiler->addViewDirective('alert');
Includes Blade Compiler directives and template formats.
- Statements
- Directives
Start or add a section;
section(string $name, string $content = null)
$name
- Section name;
$content
- Section content.
End and register current section.
endsection()
Display a section.
yield(string $name): string
$name
- Section name.
Display parent section.
parent(): string
End and display current section.
show(): string
Example 1:
@section("hello-world", "Hello")
@section("hello-world")
@parent World!
@endsection
@yield("hello-world")
Output:
Hello World!
Example 2:
@section("hello-world")
Hello
@endsection
@section("hello-world")
@parent World!
@show
Output:
Hello World!
Start a pusher or push contents in the stack.
push(string $name, string $content = null)
$name
- Stack name;
$content
- Stack content.
End current pusher and add it to the stack.
endpush()
Display contents from the stack.
stack(string $name): string
$name
- Stack name.
@push("js", "<script>alert('Foo')</script>")
@push("js")
<script>alert('Bar')</script>
@endpush
@stack("js")
Output:
<script>alert('Foo')</script>
<script>alert('Bar')</script>
Extend template with another template file.
extends(string $name)
$name
- Template file.
Extend template with another template string.
extendsString(string $id, string $string)
$id
- Template unique id. It should has the compiler extension;
$string
- Template string.
Display parent content.
content(): string
Create a template layout.blade.php
:
<section class="content">
@content
</section>
Extend layout
template:
@extends("layout")
Hello World!
Output:
<section class="content">
Hello World!
</section>
Render a template file with current parameters.
render(string $name, array $params = []): string
$name
- Template file;
$params
- Template custom parameters.
Render a template file with current parameters if template exists. See render directive.
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.
Render a template string with current parameters if its compiler exists. See renderString directive.
@render("foo")
@renderIfExists("bar")
Render a template file with new parameters.
partial(string $name, array $params = []): string
$name
- Template file;
$params
- Template custom parameters.
Render a template file with new parameters if template exists. See partial directive.
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 directive.
@partial("foo")
@partialIfExists("bar")
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 directive.
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 its compiler exists. See eachString directive.
@each("foo", [1, 2])
@renderIfExists("bar", [1, 2])
Execute a directive registered in the Viewer Contract.
format(string $name, mixed ...$args)
Example:
@format("alert", "I am a javascript alert!")
<!-- or -->
@alert("I am a javascript alert!")