开发者

Symfony: Is it possible to put elements inside a link_to tag?

I'm using Symfony 1.4 and wondering whether it's possible to achieve the following:

<a href="#"><span>Text</span></a>

... using Symfony's link_to helper?

Of course, it's possible to do this:

<a href="<?php echo url_for('#') ?>">开发者_如何学编程;<span>Text</span></a> 

But I'm wondering if there's a simpler way to do it, especially as combining i18n with the above will produce:

<a href="<?php echo url_for('#') ?>"><span><?php echo __('Text') ?></span></a> 

... a tag soup basically.

Thanks.


YOu can do it two ways...

Option 1

<?php echo link_to("<span>".__('Text')."</span>", $url); ?>

Option 2

<?php echo content_tag('a',  "<span>".__('Text')."</span>", array('href' => url_for($url))); ?>


There's also:

<?php echo link_to(content_tag('span', __'Text', array('class' => 'span-class')), '@route', array('class' => 'link-class'));

I added the attribute class for each of the two HTML tags as options if you need to extend that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜