cocoon-projet / template
Un moteur de template pour le language php
0.0.3
2025-03-19 11:29 UTC
Requires
- php: ^8.0
- nesbot/carbon: ^2
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: 3.*
- tracy/tracy: ^2.10
This package is auto-updated.
Last update: 2025-04-09 05:39:54 UTC
README
Cocoon Template Engine
Un moteur de template PHP simple et puissant, inspiré de Twig et Blade.
Pré-requis
Installation
composer require cocoon-projet/template
Configuration
use Cocoon\View\Twide; Twide::init([ 'views' => 'resources/views', 'cache' => 'temp/views', 'extension' => '.tpl.php' ]);
Extensions Disponibles
Extensions par défaut
- TextExtension : Manipulation de texte
- DateExtension : Gestion des dates
- ArrayExtension : Manipulation des tableaux
Syntaxe de Base
Variables
{{ variable }}
{{ user.name }}
{{ numbers[0] }}
Conditions
@if(condition) Contenu @elseif(autre_condition) Contenu alternatif @else Contenu par défaut @endif
Boucles
@foreach(items as item) {{ item.name }} @endforeach @for(i = 0; i < 10; i++) {{ i }} @endfor
Layouts et Sections
@layout('layout') @section('content') Contenu de la page @endsection @endlayout
Extensions
TextExtension
{{ 'texte'|excerpt(50) }} {{ 'titre'|slug }} {{ 'texte'|wordcount }} {{ 'texte'|str_starts_with('prefix') }}
DateExtension
{{ date|timeago }} {{ date|age }} {{ date|calendar }} {{ date|duration }} {{ is_future(date) }} {{ is_past(date) }}
ArrayExtension
{{ array|sort('name') }} {{ array|filter('status', 'active') }} {{ array|map('id') }} {{ array|unique }} {{ array|first }} {{ array|last }}
Licence
MIT