develhopper / primal
free and open source php templating system
1.5.1
2021-12-13 10:05 UTC
README
Yet another templating engine library
Documentation
Installation
composer require develhopper/primal
Examples
Initialize Primal
<?php use Primal\Primal; $primal = Primal::getInstance([ 'views_dir' => 'views directory', 'cache_dir' => 'directory path for caching' ]); $primal->view("viewname.html",[ 'arg1' => 'value' ]); // it will print the content of the view file
Views Syntax
Print a variable
<h1>
{{$variable}}
</h1>
Execute a Function
{% var_dump($array); %}
Include another view
@include('viewname.html')
Place holder
"base.html"
<body>
@yield('content')
</body>
Extend from another view
@extend('base.html')
Fill Placeholder in base.html with content by @section
@extend('base.html') @section('content') <h1>{{$title}}</h1> <p>{{$content}}</p> @endsection
If Else and elseif Statements
@if($variable == "foo") <p>foo</p> @elseif($variable == "bar") <p>bar</p> @else <p>foobar</p> @endif
For and Foreach Loops
@for($i=0;$i<100;$i++) <p>{{$i}}</p> @endfor @foreach($list as $item) <p>{{$item}}</p> @endforeach