Welcome Guest, Not a member yet? Register   Sign In
Several html elements inside an anchor tag, with CI's anchor funtion


i'm trying to get an image tag and a span tag inside an anchor tag using
CI's anchor function, to no success. Anyone has any idea how to do this?
I've succeeded in getting the image inside the tags but can't figure out how
to get the span inside there too.

Help greatly appriciated.

[eluser]Bart Mebane[/eluser]
I haven't tried it, but you should be able to use any text you want, including html tags. How about
&lt;?php echo anchor('news/article', '<img src="picture.jpg" /><span>some text</span>') ?&gt;

you can also pass a third parameter as an associative array.


[quote author="InsiteFX" date="1291200222"]you can also pass a third parameter as an associative array.


As kind of a noob to php in general i have to ask, how would one do that?

By passing an associative array you can add attributes to
the link tag - for example:
$array = array('class'=>'test');
echo anchor("home", "Link", $array);
// would produce:
<a class="test" href="http://localhost/your_app/home">Link</a>
This way you can set a css class (to set a background image for example)

See: http://ellislab.com/codeigniter/user-gui...elper.html

You can also use functions that output text inside the second argument, which will output the same text as Bart mentioned..
&lt;?php echo anchor('news/article', img('picture.jpg').'<span>some text</span>') ?&gt;

On a side note, the third parameter on the anchor function is an array that would only change the attributes of the <a> tag. Not affect the innerHTML.

again, I could be wrong.

[eluser]Dennis Rasmussen[/eluser]
If anchor() makes it too complicated for you then don't use it :S
It's just a helper for quick tags.

Personally, I stay away from the anchor tag. It makes things 10 times more complicated in my opinion

Really? I find the opposite true. Especially when it comes to making links within a loop where very little changes. I can set the assoc array once, loop while passing the text and link info, and the array. Done. But eh... to each their own.


Theme © iAndrew 2016 - Forum software by © MyBB