sradha sradha - 6 months ago 73
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

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