Setting A Template
Give PHPFront a template to render
The PHPFront::setTemplate()
function is used to assign a template to render.
Any valid HTML markup can serve as a template - there are no special tags needed nor any template syntax to learn.
Given PHPFront, every HTML file is plug-n-play.
Function
PHPFront::setTemplate($template );
The $template
parameter provides the template to use in either of two ways:
- A path to the template file. Both relative and absolute paths are accepted,
- A markup string that represents a valid markup document.
Usage
// Using a relative path
$PHPFront->setTemplate('../../resources/template.html');
// Using an absolute path
$PHPFront->setTemplate('c://xamp/htdocs/app/resources/template.html');
// This sets a remote template
$PHPFront->setTemplate('http://www.example.com/templates/template.html');
// Providing a template as markup string
$template = '
<!DOCTYPE html>
<html>
<head>
<title>Sample Template</title>
</head>
<body>
<p>Hello world!</p>
</body>
</html>';
$PHPFront->setTemplate($template);
PHPFront throws Exception when the file path could not be found or the markup string is empty.
Once a template is set, we can render.
$PHPFront->render();
// We can assign another template and render again with the same setup and data
$PHPFront->setTemplate('../../resources/template2.html');
$PHPFront->render();
Summary
-
The
PHPFront::setTemplate()
function provides a template to render. Recall
We've digested this key area of PHPFront!