Jeremy
Jeremy

Reputation: 3809

How do you output Fat Free PHP variable as HTML?

I am trying to output a variable from F3 which contains HTML.

$message = "<p>Hello, <b>World</b></p>"

I am outputting it as follows:

<div class="container">
    {{ @message }}
</div>

The problem is it displays exactly like so:

"<p>Hello, <b>World</b></p>"

Instead of just:

Hello, World

Upvotes: 2

Views: 1082

Answers (2)

Rayne
Rayne

Reputation: 2660

Another solution is to disable the automatic HTML escaping.

$f3 = Base::instance();
$f3->set('ESCAPE', false);

The rendered template will look like the following:

<div class="container">
    <p>Hello, <b>World</b></p>
</div>

Now it's necessary to escape untrusted data with the esc macro. Example:

{{ @message | esc }}

See also:

Upvotes: 2

MonkeyZeus
MonkeyZeus

Reputation: 20737

Per their docs:

<div class="container">
    {{ @message | raw }}
</div>

Source

Upvotes: 5

Related Questions