I am try add <b>
tag inside <a>
in cake php
I need output like that
<a href="/carsdirectory/users/logout"><b>Logout</b></a>
but i dont how to add tag in this code
<?php echo $this->Html->link('Logout', '/users/logout'); ?>
Please keep in mind that styling should not be part of your HTML Output and - as already suggested by my previous posters - should be in your CSS.
However, there you go (note the escape=false
):
echo $this->Html->link(
'<b>' . __('Logout') . '</b>',
array(
'controller' => 'users',
'action' => 'logout',
),
array(
'escape' => false,
)
);
or even more HtmlHelper magick:
echo $this->Html->link(
$this->Html->tag('b', __('Logout')),
array(
'controller' => 'users',
'action' => 'logout',
),
array(
'escape' => false,
)
);
Edit: added Ish Kumar's suggestion for localisation, in cakephp 2.0 we don't need the "true" anymore ;)
One more thing: if you use escape=false
keep in mind to sanitize the tags content (in this case the <b>Logout</b>
) by yourself, especially if its generated user content e.g. <b>$userInputVar</b>
.
My advice would be don't try to use the helpers for every single task, additionally you should use CSS to add bold to the logout link.
echo $this->Html->link('Logout', array('controller'=>'users', 'action'=>'logout'), array('class' => 'logout'));
Then in your CSS:
.logout {
font-weight: bold;
}
Update: If you REALLY REALLY must use deprecated HTML tags in your code:
echo $this->Html->link('<b>Logout</b>', array('controller'=>'users', 'action'=>'logout'), array('class' => 'logout', 'escape' => false));
That's the equivalent of doing this:
<b><?php echo $this->Html->link('Logout', '/users/logout'); ?></b>
As Dunhamzzz noted, you're better off using a CSS class and styling it that way.