Template
extends BaseContent
in package
Implement template setup object
In the fileAccess context most contents are children of this class. With this class the DAB for templates is implemented. Templates are named objects.
Tags
Table of Contents
- $ : bool|null
- $_extension : object|null
- Extension from functions.php
- $_manifests : array<string|int, mixed>|null
- $_parent : Template|null
- The parent template
- $hook : object|null
- A hook class instance, when defined
- $rootFolder : string|null
- internal root folder path
- __construct() : mixed
- Construct a new template object
- __get() : bool|mixed|null
- AddFolder() : Result
- Add a template folder
- AddManifest() : Result
- ContentSecurityPolicyHeader() : null|string
- Get the csp header of the root template parent
- Delete() : mixed
- DeleteFileOrFolder() : Result
- Delete file or folder insideof this template storage path
- DisableCdn() : bool
- Disable all cdn links in this template
- Duplicate() : Result
- Copy the element Copy the template with additional information
- EditFile() : Result
- Replace the content of a certain file in the template
- Extension() : object|null
- Get extension Get an instance of the functions class next to the template
- ExtensionJS() : string|null
- Path to admin extension js file
- Files() : array<string|int, File>|null
- List files of template
- GetCodeFilePath() : string
- Load template path
- GetHook() : null|object
- Get hook
- GetIndex() : string
- GetRootFolder() : string|null
- GetVersion() : string|null
- Core templates will not expose a version
- IsSystem() : bool
- Is a system template?
- Manifests() : array<string|int, File>
- Get configured manifests
- Parent() : Template|null
- Get the parent
- Positions() : array<string|int, string>
- List positions / Set positions
- RenameFolder() : Result
- Rename a template folder
- Save() : mixed
- ToPlainObject() : stdClass
- Convert to stdClass
- Update() : Result|null
- UpdateFile() : Result|null
- Update a file Create or update a template file of the template with given data
- UploadFile() : Result
- Upload a file to this template folder
- pathToCacheFile() : string
- prepareDetailPath() : string
- Prepare the detail template path
- prepareIndex() : string
- resolveParentStatics() : string
- Resolve static includes
Properties
$
public
bool|null
$
is_adopted_sibling
$_extension
Extension from functions.php
private
object|null
$_extension
= null
$_manifests
private
array<string|int, mixed>|null
$_manifests
= null
$_parent
The parent template
private
Template|null
$_parent
= null
$hook
A hook class instance, when defined
private
object|null
$hook
= null
$rootFolder
internal root folder path
private
string|null
$rootFolder
= null
Methods
__construct()
Construct a new template object
public
__construct(string $path[, string|null $language = null ]) : mixed
Parameters
- $path : string
-
The name or the path to the template
- $language : string|null = null
-
The object language or null for raw one
Return values
mixed —__get()
public
__get(string $name) : bool|mixed|null
Parameters
- $name : string
Return values
bool|mixed|null —AddFolder()
Add a template folder
public
AddFolder(string $base, string $name) : Result
Parameters
- $base : string
-
The root path relative to the template base path
- $name : string
-
New name for the folder
Return values
Result —A system result object
AddManifest()
public
AddManifest(string $name) : Result
Parameters
- $name : string
Return values
Result —ContentSecurityPolicyHeader()
Get the csp header of the root template parent
public
ContentSecurityPolicyHeader() : null|string
Return values
null|string —Delete()
public
Delete([mixed $skip = false ]) : mixed
Parameters
- $skip : mixed = false
Return values
mixed —DeleteFileOrFolder()
Delete file or folder insideof this template storage path
public
DeleteFileOrFolder(string $_path) : Result
Parameters
- $_path : string
-
The relative path
Return values
Result —The result of the call
DisableCdn()
Disable all cdn links in this template
public
DisableCdn() : bool
Return values
bool —Duplicate()
Copy the element Copy the template with additional information
public
Duplicate(array<string|int, mixed> $payload) : Result
Parameters
- $payload : array<string|int, mixed>
-
New element definitions
Return values
Result —A system result object
EditFile()
Replace the content of a certain file in the template
public
EditFile(string $_path, string $content) : Result
Parameters
- $_path : string
-
Relative file path
- $content : string
-
The new content for the file
Return values
Result —A system result
Extension()
Get extension Get an instance of the functions class next to the template
public
Extension() : object|null
Return values
object|null —ExtensionJS()
Path to admin extension js file
public
ExtensionJS() : string|null
Return values
string|null —Files()
List files of template
public
Files([string|null $sub_folder = null ]) : array<string|int, File>|null
Function is available for custom templates only
Parameters
- $sub_folder : string|null = null
-
A relative sub folder path
Return values
array<string|int, File>|null —The list of files or, null when not accessible
GetCodeFilePath()
Load template path
public
GetCodeFilePath(string $name[, string $ext = 'html' ], int $depth[, bool $self_only = false ]) : string
Abstract method to load the path to a file from assigned template object will return null if file not found or template not registered
Parameters
- $name : string
-
Name of the template file that
- $ext : string = 'html'
-
File extension of searched template
- $depth : int
-
Recursion depth secure flag
- $self_only : bool = false
-
Only search in own folder
Return values
string —Absolute path to the template or null if none was found
GetHook()
Get hook
public
GetHook(Folder $tree, Request $request) : null|object
Get an instance of the registered hook functions or, the parent hook of the template
Parameters
Return values
null|object —GetIndex()
public
GetIndex([string $type = 'html' ]) : string
Parameters
- $type : string = 'html'
Return values
string —GetRootFolder()
public
GetRootFolder() : string|null
Return values
string|null —GetVersion()
Core templates will not expose a version
public
GetVersion() : string|null
Return values
string|null —IsSystem()
Is a system template?
public
IsSystem() : bool
Return values
bool —The status
Manifests()
Get configured manifests
public
Manifests() : array<string|int, File>
Return values
array<string|int, File> —Parent()
Get the parent
public
Parent() : Template|null
When this instance has a parent template, load it and expose it as instance. This method is cached locally
Return values
Template|null —The parent or, null
Positions()
List positions / Set positions
public
Positions([array<string|int, mixed>|null $np = null ]) : array<string|int, string>
Return an array of positions for dynamic contents that this template provides. It will return the positions of the parent template as well.
Parameters
- $np : array<string|int, mixed>|null = null
-
The new positions
Return values
array<string|int, string> —The linked positions and the positions of the parent
RenameFolder()
Rename a template folder
public
RenameFolder(array<string|int, mixed> $base, string $name) : Result
Parameters
- $base : array<string|int, mixed>
-
The root path relative to the template base path as array of path components
- $name : string
-
New name for the folder
Return values
Result —A system result object
Save()
public
Save([mixed $force_new_id = false ]) : mixed
Parameters
- $force_new_id : mixed = false
Tags
Return values
mixed —ToPlainObject()
Convert to stdClass
public
ToPlainObject([string|null $language = null ][, bool $with_parent = true ]) : stdClass
Makes a plain object from this instance including the values of the index and the text index.
Parameters
- $language : string|null = null
-
The target translate language
- $with_parent : bool = true
-
Resolve with parent instance
Return values
stdClass —The template contents
Update()
public
Update(array<string|int, mixed> $payload) : Result|null
Parameters
- $payload : array<string|int, mixed>
Return values
Result|null —UpdateFile()
Update a file Create or update a template file of the template with given data
public
UpdateFile(string $path, string $file, string $data) : Result|null
Parameters
- $path : string
-
Sub folder of this root folder
- $file : string
-
The file name
- $data : string
-
The contents of the new file
Return values
Result|null —UploadFile()
Upload a file to this template folder
public
UploadFile(string $target, array<string|int, mixed> $data) : Result
Parameters
- $target : string
- $data : array<string|int, mixed>
Return values
Result —pathToCacheFile()
private
pathToCacheFile(string $name, string $ext) : string
Parameters
- $name : string
- $ext : string
Return values
string —prepareDetailPath()
Prepare the detail template path
private
prepareDetailPath(string $name, string $ext, int $depth) : string
Parameters
- $name : string
-
The template name
- $ext : string
-
The file extension
- $depth : int
-
The parental resolve depth
Return values
string —The path to the file
prepareIndex()
private
prepareIndex(string $name, string $ext, int $depth) : string
Parameters
- $name : string
- $ext : string
- $depth : int
Return values
string —resolveParentStatics()
Resolve static includes
private
resolveParentStatics(string $parent_source) : string
Even if this method was intentionally designed for parent includes it resolves all template statics. It adds relative and absolute include paths for certain includes like css files and images.
On top it enables the support of smarty like include syntax {include file=""} but only for one level depth.
Parameters
- $parent_source : string
-
The absolute path to template file
Return values
string —The resolved template data as string