1

I want to replace text with a fontawesome icon in a link being created with CakePHP's HTMLhelper.

Here is the text version that works just fine:

Html->link('View', ['action' => 'view', $menuitem->id], ['title' => __('View'),'class' => 'btn btn-info btn-xs']) ?>

And here is an example of what I want to accomplish:

Html->link('span with icon goes here', ['action' => 'view', $menuitem->id], ['title' => __('View'),'class' => 'btn btn-info btn-xs']) ?>

Any ideas would be helpful. Thx!

2 Answers 2

7

Use the escape option, ex:

<?= $this->Html->link(
    '<span class="fa fa-search"></span><span class="sr-only">' . __('View') . '</span>',
    ['action' => 'view', $menuitem->id],
    ['escape' => false, 'title' => __('View'), 'class' => 'btn btn-info btn-xs']
) ?>

From the docs:

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.

echo $this->Html->link(
     $this->Html->image("recipes/6.jpg", ["alt" => "Brownies"]),
     "recipes/view/6",
     ['escape' => false] );
0
0
<?= $this->Html->link('' ,['id' => 'logo',
'controller' => 'Pages', 'action' => 'display', 'home'], 
['class' => 'navbar-brand page-scroll']) ?>

I just set the image in the css and displayed like this

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.