Support the ongoing development of Laravel.io →
Views Blade

Hello,

I am trying to parse blade from a database value but it just doesn't work. I have a template for my posts, and in this template, it returns the post content using {{ $post->content }}. The $post->content contains something like {{ time() }} for example.

The problem is, it just puts the generated PHP code into the browser. It does not echo it, it just places it in the source code like this:

<!-- BLOG POST CONTENT START -->
<h1>Hosting</h1>
<?php echo time(); ?>

I am trying to echo it using this code from my template:

{{ Blade::compileString($post->content); }}

Does someone have any idea if it is even possible to do it like this?

Thanks!

Last updated 2 years ago.
0

Try using {!! !!} instead.

0

mengidd said:

Try using {!! !!} instead.

Thanks for your reply. I forgot to mention that I'm running Laravel 4. It's not escaped so that could not be the problem.

Last updated 9 years ago.
0

This does not get evaluated by default. You have to eval() it yourself.

edit: check this http://sharpten.com/blog/2014/08/15/explicitly-parsing-blade-code-laravel-4.html#sthash.m9JIliFb.dpbs

Last updated 9 years ago.
0

Thanks for your reply.

I have seen that one indeed, but I do not know where to put the code.. do you have any idea where I could/should put it? Also I tried to use eval() while echoing the $post->content, it just didn't do anything. Just a white space. Maybe this is a fix for the problem I had.

Giovani

0

Sign in to participate in this thread!

Eventy

Your banner here too?

GiovanniK giovannik Joined 5 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.