简体   繁体   中英

How to add <b> tag in HTML helper

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'); ?>

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));

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 eg <b>$userInputVar</b> .

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM