class TemplateRender

Class TemplateRender

Traits

Trait Singleton, This class ensures that all class that use this have only one instance of itself if called as: Class::getInstance()

Constants

SKINS_FOLDER

Folder containing the skins.

Each subfolder is a skin (configuration that modifies the visual aspect of the application) Each template will be a folder whose name will be the one that will appear in the template selector.

TEMPLATES_FOLDER

Folder containing the different twig templates

COMMON_TEMPLATES_FOLDER

Folder that contains templates common to the entire application, but that can be overwritten.

Properties

static protected bool $singletonArray Set to true if you want use more that one singleton using and index param in getInstance from Singleton
static protected string $basePath The base path where config files are placed. from Singleton
static private string $className Name of the class from Singleton
static private array $instances Hold the classes on instance. from Singleton
protected bool $separateConfigFile Set to true if you want to save configuration in a separate file from Singleton
static protected Environment $twig The renderer.
static protected string|null $template The template to use.
static protected string|null $skin The skin to use.
static protected string $commonTemplatesFolder Indicates the folder where the files common to all the templates are located.
static private string $currentSkin It's the name of the skin that is being used.
static private string $templatesFolder It is the skin, that is, the folder that contains the templates.
static private array $templatesFolders Array of all templates folders.
static private array $templateVars Contains the template vars.
static private FilesystemLoader $loader Template loader from filesystem.

Methods

static TemplateRender
getInstance()

Return this instance.

static string
getClassName()

Returns the class name.

from Singleton
bool
setConfig(array $params, bool $merge = true, string $index = 'main')

Save config to file.

from Singleton
array
getYamlContent()

Returns the content of the Yaml file.

from Singleton
string
getFilePath()

Return the full file config path.

from Singleton
string
getFileName()

Return the file name.

from Singleton
static string
yamlName()

Return the classname for yaml file.

from Singleton
bool
fileExists(string $filename)

Returns if file exists.

from Singleton
array
getConfig(string $index = 'main')

Returns the yaml config params.

from Singleton
static array
getDefaultValues()

Return default values

string
getBasePath()

Return the base path.

from Singleton
initSingleton()

Initialization, equivalent to __construct and must be called from main class.

from Singleton
__construct()

TemplateRender constructor.

setSkin(string $skin)

Set a skin.

setTemplatesFolder(string $template)

Establish a new template. The parameter must be only de template name, no the path!

string
getTemplatesFolder()

Return the template folder path.

array
getPaths()

Returns a list of available paths.

string
getCommonTemplatesFolder()

Return the common template folder path.

addDirs(array $folders = [])

Add additional language folders.

$this
setTwig(Environment $twig)

Sets a new twig environment.

string
render(array $data = [])

Renders a template.

Environment
getTwig()

Return the full twig environtment.

array
getOptions()

Returns a list of options.

void
addExtensions()

Add extensions to skin render.

loadPaths()

Load paths, including modules.

string|null
getTemplate()

Return the assigned template to use.

array
getTemplateVars(array $vars = [])

Return a list of template vars, merged with $vars,

$this
setTemplate(string|null $template)

Sets the new template to use.

bool
hasTemplate()

Returns true if a template has been specified.

addVars(array $vars = [])

Add vars to template vars.

array
getSkins()

Returns an array with the list of skins (folders inside the folder specified for the templates).

string
getResourceUri(string $path)

Check different possible locations for the file and return the corresponding URI, if it exists.

string
getTemplatesUri()

Return the template folder path from uri.

string
getCommonTemplatesUri()

Return the common template folder path from uri.

Details

at line 215
static TemplateRender getInstance()

Return this instance.

Return Value

TemplateRender

in Singleton at line 88
static private string getClassName()

Returns the class name.

Return Value

string

in Singleton at line 103
bool setConfig(array $params, bool $merge = true, string $index = 'main')

Save config to file.

Parameters

array $params
bool $merge
string $index

Return Value

bool

in Singleton at line 130
private array getYamlContent()

Returns the content of the Yaml file.

Return Value

array

in Singleton at line 152
string getFilePath()

Return the full file config path.

Return Value

string

in Singleton at line 162
string getFileName()

Return the file name.

Return Value

string

in Singleton at line 172
static string yamlName()

Return the classname for yaml file.

Return Value

string

in Singleton at line 184
protected bool fileExists(string $filename)

Returns if file exists.

Parameters

string $filename

Return Value

bool

in Singleton at line 196
array getConfig(string $index = 'main')

Returns the yaml config params.

Parameters

string $index

Return Value

array

at line 225
static array getDefaultValues()

Return default values

Return Value

array

in Singleton at line 215
string getBasePath()

Return the base path.

Return Value

string

in Singleton at line 223
protected initSingleton()

Initialization, equivalent to __construct and must be called from main class.

at line 122
__construct()

TemplateRender constructor.

at line 148
setSkin(string $skin)

Set a skin.

Parameters

string $skin

at line 162
setTemplatesFolder(string $template)

Establish a new template. The parameter must be only de template name, no the path!

Parameters

string $template

at line 172
string getTemplatesFolder()

Return the template folder path.

Return Value

string

at line 182
array getPaths()

Returns a list of available paths.

Return Value

array

at line 205
string getCommonTemplatesFolder()

Return the common template folder path.

Return Value

string

at line 235
addDirs(array $folders = [])

Add additional language folders.

Parameters

array $folders

at line 253
$this setTwig(Environment $twig)

Sets a new twig environment.

Parameters

Environment $twig

Return Value

$this

at line 266
string render(array $data = [])

Renders a template.

Parameters

array $data An array of parameters to pass to the template

Return Value

string The rendered template

at line 291
private Environment getTwig()

Return the full twig environtment.

Return Value

Environment

at line 304
private array getOptions()

Returns a list of options.

Return Value

array

at line 319
private void addExtensions()

Add extensions to skin render.

Return Value

void

at line 337
private loadPaths()

Load paths, including modules.

at line 366
string|null getTemplate()

Return the assigned template to use.

Return Value

string|null

at line 378
private array getTemplateVars(array $vars = [])

Return a list of template vars, merged with $vars,

Parameters

array $vars

Return Value

array

at line 390
$this setTemplate(string|null $template)

Sets the new template to use.

Parameters

string|null $template

Return Value

$this

at line 401
bool hasTemplate()

Returns true if a template has been specified.

Return Value

bool

at line 411
addVars(array $vars = [])

Add vars to template vars.

Parameters

array $vars

at line 421
array getSkins()

Returns an array with the list of skins (folders inside the folder specified for the templates).

Return Value

array

at line 443
string getResourceUri(string $path)

Check different possible locations for the file and return the corresponding URI, if it exists.

Parameters

string $path

Return Value

string

at line 466
string getTemplatesUri()

Return the template folder path from uri.

Return Value

string

at line 476
string getCommonTemplatesUri()

Return the common template folder path from uri.

Return Value

string