We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Volt or View? What to use in standalone

The Problem

I have a very small JSON-RPC service which formats standardised data to a given template, so say I can go

$mycoolservice->jsonToTemplate($myCoolJson, $myCoolTemplate);

But likewise I could also do

$mycoolservice->jsonToTemplate($myCoolJson, $myOtherCoolTemplate);

or indeed

$mycoolservice->xmlToTemplate($myCoolXml, $myCoolTemplate);

and it returns a string, with the data in whatever format translated to the template, also in whatever format. I'd like to use Volt as the template engine, but how do I use it in such a way that I can call it like this (roughly)?

function service ($string, $var1, $var2, $var3) {


$myCoolService->tom = $var1;

$myCoolService->dick = $var2;

$myCoolService->harry = $var3;

return $myCoolService->render();


Naturally, they don't have to be those specific function names, it's indended as sort-of pseudocode

Thanks very much, Phalcon dudes

edited Oct '15


This thread is perhaps helpful. Check Oleg's 2nd (and 1st) answer - the Volt compiler returns php code, which you can parse to string by evalling it.