Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



5.7k
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!



5.7k
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



752
Accepted
answer

This is fixed here