Razor syntax PHP equivalent

Viewed 13622

Is there an equivalent to the new ASP.NET razor syntax in PHP?

8 Answers

I'm actually working on a project that does exactly that! Just with a $ instead of a @.

It's called Phazor for Node.

Just install it npm i phazor -g

<head>
    /* Phazor comments inside html */
    ${
        // Vanilla PHP inside ${ }
        $title = "I love fruit";
        $isFruit = true;
    }

    /* An echo expression */
    <title>$(ucwords($title))</title>
</head>
<body>

    /* Variable expression */
    <h1>$title.</h1>

    /* Inline statement */
    $if ($isFruit) {
        <p>It sure is great!</p>
    }
</body>

Then run phazor sourceFolder destinationFolder and it will compile all the phazor .ph files into the destination folder. (It can also compile TypeScript and SASS files inside the folder)

Keep in mind this is not fully tested in a production environment.

Related