Introduction
Devflow uses Scaffold:Native by default.
Scaffold:Native Engine
Scaffold:Native is not a compiler template engine. It uses native PHP syntax similar to Plates and FoilPHP. Like majority
of template engines, Scaffold:Native supports inheritance through blocks. Furthermore, child templates declare blocks
that can be overridden, extended and displayed by parent templates.
All Scaffold:Native templates must follow the namepace::/path/to/template format.
<?php
$this->parent('main::layout');
$this->block('content', function ($params) {
?>
<article>
<header>
<h1><?=$this->esc($this->ucfirst($params['title']));?></h1>
</header>
<main>
<?php foreach($params['paragraphs'] as $paragraph): ?>
<p>
<?=$this->esc($paragraph);?>
</p>
<?php endforeach; ?>
</main>
</article>
<?php }); ?>
<html>
<head>
<title><?=$this->esc($title);?></title>
</head>
<body>
<?=$this->block('content');?>
</body>
</html>
Namespace and function callbacks are registered with the templating engine when it is constructed. Function callbacks
area available as methods within the template context and must be callable.
The default template extension is phtml, and all Devflow template files live in the resources/views folder. When you
are creating your views, it is recommended that you place them in the Cms/views folder.
<?php
declare(strict_types=1);
namespace Application\Http\Controller;
use Psr\Http\Message\ResponseInterface;
use Qubus\View\Native\Exception\InvalidTemplateNameException;
use Qubus\View\Native\Exception\ViewException;
use function Codefy\Framework\Helpers\view;
use function Qubus\Security\Helpers\die__;
final class MyController
{
/**
* @throws ViewException
* @throws InvalidTemplateNameException
*/
public function index(): ResponseInterface
{
$params = [
'title' => 'Devflow CMF',
'paragraphs' => [
'My first paragraph.',
'My second paragraph.',
],
];
try {
return view('cmf::home', $params);
} catch (InvalidTemplateNameException | ViewException $e) {
die__($e->getMessage());
}
}
}
Registered Function Callbacks
strip- Properly strip all HTML tags including script and style (default). This differs from PHP's native strip_tags() function because this function removes the contents of the tags.- Parameters
string $string- String containing HTML tagsbool $removeBreaks- Optional. Whether to remove left over line breaks and white space characters.string $tags- Tags that should be removed.bool $invert- Instead of removing tags, this option checks for which tags to not remove. Default: false.
- Parameters
trim- Removes all whitespace.upper- Make a string uppercase (similar toucwords).lower- Make a string lowercase.ucfirst- Uppercase the first character in a string.lcfirst- Lowercase the first character in a string.ucwords- Uppercase the first character of each word in a string.esc- Escaping for HTML output.escJs- Escaping for inline JavaScript.escUrl- Escaping for url.purify- Makes content safe to print on screen. To be used instead ofescfor escaping rich text.truncate- Truncates a string to the given length. It will optionally preserve HTML tags if$isHtmlis set to true.- Parameters
string $stringThe string to truncate.int $limitThe number of characters to truncate.string $continuationThe string to use to denote it was truncated. Default ...bool $isHtmlWhether the string has HTML.
- Parameters
concat- Concatenation with separator (strings only).- Parameters
string $string1Left string.string $string2Right string.string $separatorDelimiter to use between strings. Default: comma.string ...$stringsList of strings.
- Parameters