PHP code example of forme / platine

1. Go to this page and download the library: Download forme/platine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

forme / platine example snippets


use Forme\Platine\Engine;

$view = Engine::create('/path/to/views', 'plate.php');

echo $view->render('home', ['title' => 'Hello World']);

// views/home.plate.php
<h1><?=$v->e($title)

<?=$v->e($userInput)

 $v->layout('layouts/main')

// views/layouts/main.plate.php
<html>
<body>
    <?=$v->section('content')

 $v->layout('layouts/main', ['title' => 'My Page'])

// views/layouts/wrapper.plate.php
 $v->layout('layouts/main')

<?=$v->insert('partials/header')

<?=$v->insert('partials/header', ['title' => 'My Page'])

// calling side
 $v->component('components/card', ['title' => 'My Card'])

// views/components/card.plate.php
<div class="card">
    <div class="card-header"><?=$v->e($title)

 $v->component('components/card', ['title' => 'My Card'])

// views/components/card.plate.php
<div class="card">
    <div class="card-header"><?=$v->e($title)

$view->render('partials/foo');
$view->render('partials.foo');

$view->render('partials/foo/');
$view->render('partials.foo.');

$view->registerFunction('truncate', function(string $value, int $length = 100): string {
    return mb_strimwidth($value, 0, $length, '...');
});

<?=$v->truncate($longString, 50)

$view = Engine::createWithConfig([
    'base_dir' => '/path/to/views',
    'render_context_var_name' => 'view',
]);