Reputation: 680
I would like to use a template system like Twig (specifically the block functionality) but in plain PHP.
For example, I found http://phpsavant.com/docs/ but it seems that doesn't support blocks or anything similar.
Edit I found something that appears to have block syntax with regular PHP code: http://phpti.com/
Upvotes: 0
Views: 751
Reputation: 1261
As far as I understand use off Blade
for views is optional in Laravel
. You can use file name like view.php
instead of view.blade.php
and use plain old PHP syntax there. Only catch is you cannot have both view.php
and view.blade.php
as they both respond to
return View::make('view);
Upvotes: 0
Reputation: 7818
There is one included in the Laravel framework called Blade.
You can mix plain old PHP with the Blade templating syntax, where {{...}}
also translates to <?=...?>
or <?php echo ... ?>
Also has blocks you know in Twig, but they are called sections
.
@section('heading')
{{ strtoupper("I'm not shouting") }}
@show
<?= strtolower('Shhh!'); ?>
This is under the Illuminate\View
namespace - See on GitHub, and can be downloaded with Composer as it is also registered on Packagist - just at the following to your project's composer.json.
{
"require": {
"illuminate/view": "4.*"
}
}
I'm not certain at this point about how you'd attempt to render a template from a custom project. If I find out, I'll update my answer.
Upvotes: 1
Reputation: 20155
PHP is a templating language(yes it is) , blocks can be implemented with buffers :
<?php
ob_start();
?>
this the content of the block for <?= date("Y-m-d") ?>
<?php
$content = ob_get_clean();
then in the main layout echo the content of the blocks :
echo $head;
echo $content ;
// ....
in fact that is what most template engines are using.
using template libs have huge advantages though ( caching , escaping by default ,etc ... )
Upvotes: 0
Reputation: 1570
Symfony (which uses Twig by default) also has a php-based template system that works very much like Twig. It has template inheritance and uses 'slots', which are equivalent to Twig's blocks. It's a stand-alone library that can be used outside of the full Symfony framework.
http://symfony.com/doc/2.0/cookbook/templating/PHP.html
Upvotes: 0