Creating Views
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::relative/path/to/template format.
<?php
$this->parent('cmf::layout');
$this->block('frontend', 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('frontend');?>
    </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 you can place your custom views in CMs/views.
<?php
declare(strict_types=1);
namespace App\Infrastructure\Http\Controllers;
use Codefy\Framework\Http\BaseController;
use Qubus\View\Native\Exception\InvalidTemplateNameException;
use Qubus\View\Native\Exception\ViewException;
use function Qubus\Security\Helpers\die__;
final class HomeController extends BaseController
{
    /**
     * @throws ViewException
     * @throws InvalidTemplateNameException
     */
    public function index(): ?string
    {
        $params = [
            'title' => 'CodefyPHP Framework',
            'paragraphs' => [
                'My first paragraph.',
                'My second paragraph.',
            ],
        ];
        try {
            return $this->view->render('cmf::index', $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 tags
- bool $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 to- ucwords).
- 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 of- escfor 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