Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top