sradha sradha - 2 years ago 174
HTML Question

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

Answer Source

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')),
        ['escape' => false,'class' => 'btn btn-primary']


echo $this->Html->link(
    '<i class="fa fa-eye"></i>',
    ['escape' => false,'class' => 'btn btn-primary']

Visit Cake's docs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download