brbunny/brplates

BrPlates is a component for handling view layer using Plates

v1.3.0 2023-05-12 19:21 UTC

This package is auto-updated.

Last update: 2024-11-12 22:17:16 UTC


README

Maintainer PHP from Packagist Latest Version Software License Total Downloads

BrPlates is a component for handling view layer using Plates

Installation

BrPlates is available through Composer:

"brbunny/brplates": "1.2.*"

or run

composer require brbunny/brplates

Documentation

For more details on how to use BrPlates, see the example folder with details in the component directory or to learn more visit PlatesPHP

Initialization

To start using BrPlates, instantiate the class inside your controller. To learn more, visit PlatesPHP

Para começar a usar o BrPlates, instancie a classe dentro do seu controlador. Para saber mais, visite PlatesPHP

<?php

use BrBunny\BrPlates\BrPlates;

class Controller
{
    /** @var BrPlates; */
    private $view;

    public function __construct($path, $ext)
    {
        // $this->view = new BrPlates($path, $ext);
        $this->view = new BrPlates($path); //Extension is optional
    }
}
function

Create a unique function for a specific use.

Criar uma função única para um caso específico.

<?php

// Register a one-off function
$this->view->function("name", function ($params) {
    // Type Code
});
path and removePath

Group your models in different namespaces.

Agrupe seus modelos em diferentes namespaces.

<?php

// Get template from another directory
$this->view->path("profile", "./theme/profile");

//Use template
$this->view->show("profile::profile", ["user" => "Jow User"]);

// Remove template added
$this->view->removePath("profile");
data

If you have data in common across multiple models, use the data() function.

Se possuir dados em comum em vários modelos utilize a função data().

<?php
//
$this->view->data(['company' => 'BrPlates'], ["_theme", "home"]);
$this->view->data(['company' => 'BrPlates']); // Template is Optional
render

If you want to store the model in a variable, use the render() function. If you want to render the model directly, use the show() function.

Se deseja armazenar o modelo em uma variável, utilize a função render(). Já se quiser renderizar o modelo direto utilize a função show().

<?php
$template = $view->render("_theme", ["user" => "Jow User"]);
echo $template;

$this->view->show("_theme", ["user" => "Jow User"]);
isset

To check if a model exists, simply use the isset() function.

Para verificar se um modelo existe, basta utilizar a função isset()

<?php

if ($this->view->isset("_theme")) {
   // Exist
}
widget

If you want to create a tree of components, use the widget()

Se você deseja criar uma árvore de componentes, utilize widget()

/*
Content of the widgets::list template:

<ul>
    <?= $this->section('widgets') ?>
</ul>
*/
<?= $this->widget("widgets::list", [/* Items */])  ?>

// Example
<?= $this->widget("widgets::list", [
    $this->child("widgets::item", ["content" => "Text"]),
    $this->child("widgets::item", ["content" => "Text2"]),
    $this->children("widgets::list2", [
        $this->child("widgets::item", ["content" => "Text3.1"]),
    ], ["label" => "Text3"])
])  ?>
children

If you have a component that has child components, and that same component contains data, use children()

Se existe um componente que possui componentes filhos, e esse mesmo componente contem data utilize children()

/*
Content of the widgets::children template:

<li>
    <?= $label ?>
    <ul>
        <?= $this->section('widgets') ?>
    </ul>
</li>
*/
$this->children("widgets::list2", [
        $this->child("widgets::item", ["content" => "Text1.1"]),
], ["label" => "Text1"]);
child

If the component doesn't have any children, use child()

Se o componente não tiver filhos, utilize child()

/*
Content of the widgets::item template:

<li><?= $content ?></li>
*/
$this->child("widgets::item", ["content" => "Text"]);
renderMinify

Reduce code to render.

Reduzir código para renderização.

<?php

echo $view->renderMinify("profile::profile", ["user" => "Jow User"]);

OBS: To minify js scripts, put "js-mix" in the opening of the script tag

OBS: Para minimizar scripts js, coloque "js-mix" na abertura da tag script

<script js-mix>
    // Alert
    alert('minify');
</script>

// Result
<script>alert('minify');</script>

Credits

License

The MIT License (MIT). Please see License File for more information.