sradha
sradha

Reputation: 2244

How to include a html element in cakephp 3.2 anchor tag?

Here i want to include a html element in cakephp 3.2 anchor link. I have tried it ,but its not working.Below is code.

  <?= $this->Html->link(__('<i class="fa fa-eye"></i>'), ['action' => 'edit', $user->id],['class'=>"btn btn-primary"]) ?>

I want below html in cake format.

<a class="btn btn-primary" href="/adminCake3/adminCake3/users/edit/3"><i class="fa fa-eye"></i></a>

Here inplace of icon ,html tag() is coming.Thank you in advance.

enter image description here

Upvotes: 1

Views: 1769

Answers (3)

Sudhir
Sudhir

Reputation: 837

Make your anchor link

$this->Html->link('<i class="fa fa-eye"></i> Edit', ['action' => 'edit', $user->id],['escape'=>false,'class'=>'btn btn-xs btn-primary']);

This is working code.

Upvotes: 0

jameshwart lopez
jameshwart lopez

Reputation: 3131

HTML special characters in $title will be converted to HTML entities. To disable this conversion, set the escape option to false in the $options array.

Setting escape to false will also disable escaping of attributes of the link.

Try this

echo $this->Html->link(
        $this->Html->tag('i','',array('class'=>'fa fa-eye')),
        '/adminCake3/adminCake3/users/edit/'.$user->id,
        ['escape' => false,'class' => 'btn btn-primary']
    );

or

echo $this->Html->link(
    '<i class="fa fa-eye"></i>',
    '/adminCake3/adminCake3/users/edit/'.$user->id,
    ['escape' => false,'class' => 'btn btn-primary']
);

Visit Cake's docs

Upvotes: 3

Sahadev
Sahadev

Reputation: 1448

User This method:

<?= $this->Html->link(__('<i class="fa fa-eye"></i>'), ['action' => 'edit', $user->id],['class'=>"btn btn-primary"],['escape'=>false]) ?>

Upvotes: 0

Related Questions