Razor syntax PHP equivalent Razor syntax PHP equivalent asp.net asp.net

Razor syntax PHP equivalent


Thanks @mindplay.dk for linking to the Razor View Renderer for the Yii Framework! I wanted to share a recent find, Twig (http://www.twig-project.org/) as an alternative if you are looking for a standalone template engine for PHP. It's not Razor syntax, but it is simple and extensible.

Here's some examples from the site:

For Each:

{% for user in users %}  * {{ user.name }}{% else %}  No user has been found.{% endfor %}

Blocks & Inheritance:

{% extends "layout.html" %}{% block content %}  Content of the page...{% endblock %}

Filters:

{{ "now"|date("m/d/Y") }}{{ "I like %s and %s."|format(foo, "bar") }}returns: I like foo and bar. (if the foo parameter equals to the foo string)

I'm still doing some preliminary development & testing with this engine and I'm liking it thus far!


There is a Razor-like view-engine for the Yii framework:

http://www.yiiframework.com/extension/razorviewrenderer

It's very simple - it doesn't seem to have any real Yii dependencies, so I can't imagine it would be very difficult to pull this out of Yii and use it in a different context.

Mind you, this is just a Razor-style template parser - it compiles Razor-style templates into plain vanilla PHP scripts. It relies on Yii for the actual view-engine.


Laravel's Blade Template Engine, uses a similar syntax to Razor. https://laravel.com/docs/master/blade