Justin John
Justin John

Reputation: 9616

Write two span tags or two elements inside an cake php link

How to write two span tags or two elements inside an cake php link in cakephp ?

For example

<?php
$title = '$this->Html->tag('span', 'Test Title', array('style' => 'color:blue'))';
$status = '$this->Html->tag('span', '  (New) ', array('style' => 'color:black'))';

echo $this->Html->link( $title.$status, 'people/video'.$person['video']['id'], 'target' => '_blank'));
?>

So that I can output

<a href="people/video/765" target ="_blank" ><span style="color: blue">Test Title</span><span style="color: #000000;"> (New) </span> </a>

Upvotes: 0

Views: 1504

Answers (1)

mensch
mensch

Reputation: 4411

$this->Html->link() automatically escapes special characters which causes HTML to be rendered as special characters. You can set escape option of $this->Html->link() to false to accomplish want, see the manual for further options.

Your updated code would look like the following. I removed the inverted commas around $title and $status and wrapped 'target' => '_blank' in an array, you can't use key => value pairs in the way you use them in your original code. Probably it was part of an array structure before, as there was an extraneous parenthesis at the end of that line.

<?php
  $title = $this->Html->tag('span', 'Test Title', array('style' => 'color:blue'));
  $status = $this->Html->tag('span', '  (New) ', array('style' => 'color:black'));

  echo $this->Html->link( $title.$status, 'people/video/'.$person['video']['id'], array('target' => '_blank', 'escape' => false));
?>

Upvotes: 2

Related Questions