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

Running Partials from dynamic content

I want to be able to have volt render a partial reference from content that is pulled fromt he database.

as an example, the string content from the database would be like this:

<h1>blah blah blah</h1> {{ partial('partials/listings') }}

I tried running volt in stand alone mode but haven't had any luck.



8.1k
edited May '14

So <h1>blah blah blah</h1> {{ partial('partials/listings') }} is the content that's in the db right?

The quick and dirty solution: use Volt\Compiler's compileString and then eval the result:

eval( ';?>' . $compiledString )

AFAIK it's not possible to parse a tpl string with Volt.. (that makes for a good NFR btw AFAIC).

It this content in your db trusted btw? Otherwise it might be better to write a parser for your content..

-- Edit: ok, who editted my reply? ;-)

I attempted running eval on the compiled string and I was able to render the PHP however it ends up being out of the views scope and returns errors that $this is not an object.

In this instance the code in the db is safe.

Thank you for the reply!



8.1k
edited May '14

Are you doing the eval inside the view/tpl itself ?

it was at the controller level, but now that I think about it I can probably run it from within the view



1.1k
Accepted
answer

This is fixed here