Symfony:是否可以将元素放在link_to标记中?

时间:2010-02-16 19:34:28

标签: symfony1 tags hyperlink helper

我正在使用Symfony 1.4并想知道是否有可能实现以下目标:

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

...使用Symfony的link_to帮助器?

当然,可以这样做:

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

但我想知道是否有一种更简单的方法,特别是将i18n与上述方法结合起来会产生:

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

...基本上是标签汤。

感谢。

2 个答案:

答案 0 :(得分:3)

你可以用两种方式做到这一点......

选项1

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

选项2

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

答案 1 :(得分:1)

还有:

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

如果您需要扩展,我会为两个HTML标记中的每一个添加属性class作为选项。

相关问题