\phpDocumentor\Plugin\Scrybe\TemplateTwig

Template class to use Twig to generate templates.

Summary

Methods
Properties
Constants
__construct()
setName()
getName()
setPath()
getPath()
setExtension()
getExtension()
decorate()
getAssets()
No public properties found
No constants found
getTemplateFilename()
getTwigEnvironment()
$path
$name
$extension
N/A
No private methods found
No private properties found
N/A

Properties

$path

$path : string

Type

string — The base location for templates

$name

$name : string

Type

string — The name of the containing template folder

$extension

$extension : string

Type

string — The extension used to select the correct template file

Methods

__construct()

__construct(string  $templatePath) 

Constructs the twig template and sets the default values.

Parameters

string $templatePath

the base location for templates.

setName()

setName(string  $name) : void

Sets the name for this template.

Parameters

string $name

A template name that may be composed of alphanumeric characters, underscores and/or hyphens.

Throws

\InvalidArgumentException

if the name does not match the prescribed format.

getName()

getName() : string

Returns the name of this template.

See setName() for a specification of the format.

Returns

string

setPath()

setPath(string  $path) : void

Sets the base path where the templates are stored.

Parameters

string $path

Throws

\InvalidArgumentException

getPath()

getPath() : string

Returns the base path where the templates are stored.

Returns

string

setExtension()

setExtension(string  $extension) : void

Sets the file extension used to determine the template filename.

The file extension of the destination format needs to be set. This is used to retrieve the correct template.

Parameters

string $extension

an extension (thus only containing alphanumeric characters and be between 2 and 4 characters in size).

Throws

\InvalidArgumentException

if the extension does not match the validation restrictions mentioned above.

getExtension()

getExtension() : string

Returns the extension of the destination file extension.

Returns

string

decorate()

decorate(string  $contents, array<mixed,string>  $options = array()) : string

Applies the relevant template upon the given content.

This method takes the combines the template with the given contents and generates a final piece of text from that.

The user may add additional options that are set as parameters in the template.

Parameters

string $contents
array<mixed,string> $options

Returns

string

getAssets()

getAssets() : array<mixed,string>

Returns a list of files that need to be copied to the destination location.

Examples of assets can be:

  • CSS files
  • Javascript files
  • Images

Assets for this template engine means every file that is contained in a subfolder of the template folder and does not end with the extension twig.

Thus every file in the root of the template folder is ignored and files and directories having only twig templates (considered as being includes) are not included in this list.

Returns

array<mixed,string>

getTemplateFilename()

getTemplateFilename() : string

Returns the filename for the template.

The filename is composed of the following components:

  • the template base folder
  • the template's name
  • a path separator
  • the literal 'layout' combined with the extension
  • and as final extension the literal '.twig'

Throws

\DomainException

if the template does not exist.

Returns

string

getTwigEnvironment()

getTwigEnvironment() : \Twig_Environment

Constructs and returns the twig environment.

This uses the path as defined with this class to instantiate a new Environment and disables the escaping mechanism since we use it to generate HTML; even embedded.

Returns

\Twig_Environment