emersonthis
emersonthis

Reputation: 33378

CakePHP: How to prevent HtmlHelper from escaping HTML tags inside label parameter

I'm trying to use the HtmlHelper to generate a post link. It's a delete link/button, but I want to user HTML in the first parameter (the label). Something like this:

echo $this->Form->postLink(
            '<i>A&nbsp;Title</i>',
            array('action' => 'delete', $project['Project']['hashed_id']),
            array('confirm' => 'Are you sure?'));

Unfortunately it just prints all the markup instead of rendering it so this is what comes out: <i>A&nbsp;Title</i> instead of: A Title.

I know I could just write it manually, but the postLink creates nonces and other magic that I want to preserve. Any ideas how I can trick CakePHP into doing what I want?

Upvotes: 0

Views: 1459

Answers (1)

Nunser
Nunser

Reputation: 4522

Try this

echo $this->Form->postLink(
            '<i>A&nbsp;Title</i>',
            array('action' => 'delete', $project['Project']['hashed_id']),
            array('escape'=>false),
            'Are you sure?');

According to the docs, the third parameter is an option array, that can have the same parameters as HtmlHelper::link. And that one has an option of

escape: Set to false to disable escaping of title and attributes.

Oh, can be also like this

echo $this->Form->postLink(
            '<i>A&nbsp;Title</i>',
            array('action' => 'delete', $project['Project']['hashed_id']),
            array('confirm'=>'Are you sure?', 'escape'=>false));

Works the same way.

Upvotes: 5

Related Questions