Reputation: 33378
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 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 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
Reputation: 4522
Try this
echo $this->Form->postLink(
'<i>A 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 Title</i>',
array('action' => 'delete', $project['Project']['hashed_id']),
array('confirm'=>'Are you sure?', 'escape'=>false));
Works the same way.
Upvotes: 5