Properties

$macros

$macros : array

The registered string macros.

Type

array

$modules

$modules : \Phug\Util\Partial\array<ModuleInterface>

Type

\Phug\Util\Partial\array

$debugString

$debugString : string

Type

string

$debugFile

$debugFile : string

Type

string

$optionEvents

$optionEvents : array

Type

array

$compiler

$compiler : \Phug\Compiler

The current compiler in use to convert Pug code into PHP code.

Type

\Phug\Compiler

Methods

hasModule()

hasModule(string|\Phug\Util\ModuleInterface  $module) : boolean

Parameters

string|\Phug\Util\ModuleInterface $module

Returns

boolean

getModules()

getModules() : \Phug\Util\Partial\array<ModuleInterface>

Returns

\Phug\Util\Partial\array

getStaticModules()

getStaticModules() : \Phug\Util\Partial\array<string>

Returns

\Phug\Util\Partial\array

addModule()

addModule(string|\Phug\Util\ModuleInterface  $module) : $this

Parameters

string|\Phug\Util\ModuleInterface $module

Returns

$this

addModules()

addModules(\Phug\Util\Partial\array<string|\Phug\Util\Partial\ModuleInterface>  $modules) : $this

Parameters

\Phug\Util\Partial\array $modules

Returns

$this

removeModule()

removeModule(string|\Phug\Util\ModuleInterface  $module) : $this

Parameters

string|\Phug\Util\ModuleInterface $module

Returns

$this

getModuleBaseClassName()

getModuleBaseClassName() : string

Returns

string

getDebugFormatter()

getDebugFormatter() : \Phug\Formatter

Returns

\Phug\Formatter

reInitOptions()

reInitOptions(  $options) 

Reinitialize debug options then set new options.

Parameters

$options

handleError()

handleError(\Throwable  $error, integer  $code, string  $path, string  $source, array  $parameters, array  $options) 

Handle error occurred in compiled PHP.

Parameters

\Throwable $error
integer $code
string $path
string $source
array $parameters
array $options

Throws

\Phug\RendererException
\Throwable

initCompiler()

initCompiler() 

Initialize/re-initialize the compiler. You should use it if you change initial options (for example: on_render or on_html events, or the compiler_class_name).

Throws

\Phug\RendererException

share()

share(array|string  $variables, mixed  $value = null) : $this

Share variables (local templates parameters) with all future templates rendered.

Parameters

array|string $variables

a variables name-value pairs or a single variable name

mixed $value

the variable value if the first argument given is a string

Returns

$this

Examples

'fr')
** File not found : $renderer->share('lang', **
=> 'My blog', 'today' => new DateTime()])
** File not found : $renderer->share(['title' **

resetSharedVariables()

resetSharedVariables() 

Remove all previously set shared variables.

cacheFile()

cacheFile(string  $path) : boolean|integer

Cache a template file in the cache directory (even if the cache is up to date).

Returns the number of bytes written in the cache file or false if a failure occurred.

Parameters

string $path

Returns

boolean|integer

cacheFileIfChanged()

cacheFileIfChanged(string  $path) : boolean|integer

Cache a template file in the cache directory if the cache is obsolete.

Returns true if the cache is up to date and cache not change, else returns the number of bytes written in the cache file or false if a failure occurred.

Parameters

string $path

Returns

boolean|integer

cacheDirectory()

cacheDirectory(string|array<mixed,string>  $directory) : array

Cache all templates in a directory in the cache directory you specified with the cache_dir option.

You should call after deploying your application in production to avoid a slower page loading for the first user.

Parameters

string|array<mixed,string> $directory

Returns

array

macro()

macro(string  $name, object|callable  $macro) : void

Register a custom macro.

Parameters

string $name
object|callable $macro

hasMacro()

hasMacro(string  $name) : boolean

Checks if macro is registered.

Parameters

string $name

Returns

boolean

__callStatic()

__callStatic(string  $method, array  $parameters) : mixed

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Throws

\BadMethodCallException

Returns

mixed

__call()

__call(string  $method, array  $parameters) : mixed

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Throws

\BadMethodCallException

Returns

mixed

__construct()

__construct(array|\ArrayAccess|null  $options = null) 

Renderer constructor.

Parameters

array|\ArrayAccess|null $options

Throws

\Phug\RendererException

getCompiler()

getCompiler() : \Phug\CompilerInterface

Get the current compiler in use. The compiler class name can be changed with compiler_class_name option and is Phug\Compiler by default.

Returns

\Phug\CompilerInterface

compile()

compile(string  $string, string  $filename = null) : string

Compile a pug template string into a PHP string.

Parameters

string $string

pug input string

string $filename

optional file path of the given template

Returns

string

compileFile()

compileFile(string  $path) : string

Compile a pug template file into a PHP string.

Parameters

string $path

pug input file

Returns

string

render()

render(string  $string, array  $parameters = array(), string  $filename = null) : string

Render a pug template string into a HTML/XML string (or any tag templates if you use a custom format).

Parameters

string $string

pug input string

array $parameters

parameters (values for variables used in the template)

string $filename

optional file path of the given template

Throws

\Phug\RendererException

Returns

string

renderFile()

renderFile(string  $path, string|array  $parameters = array()) : string

Render a pug template file into a HTML/XML string (or any tag templates if you use a custom format).

Parameters

string $path

pug input file

string|array $parameters

parameters (values for variables used in the template)

Throws

\Phug\RendererException

Returns

string

renderAndWriteFile()

renderAndWriteFile(string  $inputFile, string  $outputFile, array  $parameters = array()) : boolean

Render a pug file and dump it into a file.

Return true if the render and the writing succeeded.

Parameters

string $inputFile

input file (Pug file)

string $outputFile

output file (typically the HTML/XML file)

array $parameters

local variables

Returns

boolean

renderDirectory()

renderDirectory(string  $path, string  $destination = null, string  $extension = '.html', string|array  $parameters = array()) : array

Render all pug template files in an input directory and output in an other or the same directory.

Return an array with success count and error count.

Parameters

string $path

pug input directory containing pug files

string $destination

pug output directory (optional)

string $extension

file extension (optional, .html by default)

string|array $parameters

parameters (values for variables used in the template) (optional)

Returns

array

display()

display(string  $string, array  $parameters = array(), string  $filename = null) 

Display a pug template string into a HTML/XML string (or any tag templates if you use a custom format).

Parameters

string $string

pug input string

array $parameters

parameters or file name

string $filename

Throws

\Phug\RendererException|\Throwable

displayFile()

displayFile(string  $path, array  $parameters = array()) 

Display a pug template file into a HTML/XML string (or any tag templates if you use a custom format).

Parameters

string $path

pug input file

array $parameters

parameters (values for variables used in the template)

Throws

\Phug\RendererException|\Throwable

setDebugFile()

setDebugFile(string  $debugFile) 

Parameters

string $debugFile

setDebugString()

setDebugString(string  $debugString) 

Parameters

string $debugString

setDebugFormatter()

setDebugFormatter(\Phug\Formatter  $debugFormatter) 

Parameters

\Phug\Formatter $debugFormatter

initDebugOptions()

initDebugOptions(\Phug\Renderer  $profilerContainer) 

Parameters

\Phug\Renderer $profilerContainer

getDefaultOptions()

getDefaultOptions(  $options) 

Parameters

$options

enableModule()

enableModule(  $moduleClassName,   $className, \Phug\Util\ModuleContainerInterface  $container,   $optionName) 

Parameters

$moduleClassName
$className
\Phug\Util\ModuleContainerInterface $container
$optionName

mergeWithSharedVariables()

mergeWithSharedVariables(array  $parameters) : array

Returns merged globals, shared variables and locals.

Parameters

array $parameters

Returns

array

highlightLine()

highlightLine(  $lineText,   $colored,   $offset,   $options) 

Parameters

$lineText
$colored
$offset
$options

wrapLineWith()

wrapLineWith(  $lineText,   $offset,   $wrapper,   $shift) 

Parameters

$lineText
$offset
$wrapper
$shift

getErrorAsHtml()

getErrorAsHtml(  $error,   $parameters,   $data) 

Parameters

$error
$parameters
$data

getErrorMessage()

getErrorMessage(  $error, \Phug\Util\SourceLocation  $location,   $data) 

Parameters

$error
\Phug\Util\SourceLocation $location
$data

getRendererException()

getRendererException(  $error,   $code,   $line,   $offset,   $source,   $sourcePath,   $parameters,   $options) 

Parameters

$error
$code
$line
$offset
$source
$sourcePath
$parameters
$options

hasColorSupport()

hasColorSupport() 

getDebuggedException()

getDebuggedException(  $error,   $code,   $source,   $path,   $parameters,   $options) 

Parameters

$error
$code
$source
$path
$parameters
$options

enableModules()

enableModules() 

handleOptionAliases()

handleOptionAliases() 

synchronizeEvent()

synchronizeEvent(  $event,   $key) 

Parameters

$event
$key

createCompiler()

createCompiler(  $compilerClassName) 

Parameters

$compilerClassName