0

I have this code

<li id="Tiempo">
   <?= $this->Html->link(__('En Tiempo'), ['action' => 'index', 'Tiempo']) ?><span class="label label-success ml-10"><?php echo $entiempo ?></span>
</li>

But i want the span into a but I don't know how

1
  • Please always mention your exact CakePHP version (last line in lib/Cake/VERSION.txt or vendor/cakephp/cakephp/VERSION.txt) - thanks! Commented Apr 22, 2020 at 10:48

1 Answer 1

2

You have to modify the content/title of the link. As the docs point out, this is the first parameter of HtmlHelper->link(). To add the span inside your a tag you have 2 options.

Add the Span in the Link

You could either modify it directly and set the escape options to false:

<li id="Tiempo">
    <?= $this->Html->link('<span class="label label-success ml-10">' . $entiempo . '</span>', ['action' => 'index', 'Tiempo'], ['escape' => false]) ?>
</li>

Modify the template

Or you modify the template HtmlHelper uses.

$this->Html->setTemplates([
    'link' => '<a href="{{url}}"{{attrs}}><span class="label label-success ml-10">{{content}}</span></a>',
]);

and use the link() method like this:

<?= $this->Html->link($entiempo, ['action' => 'index', 'Tiempo']) ?>

See Changing the Tags Output by HtmlHelper

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.