Is there an equivalent to the new ASP.NET razor syntax in PHP?
cshtml files are razorpages or MVC views, they does not contain any C#-written client-side code. If you wan to do so, you must use JavaScript. However, a . razor file, also know as a Razor component, can have C# written in it and run on client's browser.
Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine.
What is Razor? Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. Server-based code can create dynamic web content on the fly, while a web page is written to the browser.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With