views:

255

answers:

2

Hi,

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.

+1  A: 

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))); ?>
prodigitalson
Beautiful, thanks
Tom
Mind you you may need to do something with the escaping for `link_to` im not completely sure - its been awhile.
prodigitalson
Ok, will have a play.
Tom
+1  A: 

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.

Raise