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

[eluser]Joures[/eluser]
Hi,

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.
#2

[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
Code:
&lt;?php echo anchor('news/article', '<img src="picture.jpg" /><span>some text</span>') ?&gt;
#3

[eluser]InsiteFX[/eluser]
you can also pass a third parameter as an associative array.

InsiteFX
#4

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

InsiteFX[/quote]

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

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

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

[eluser]teampoop[/eluser]
You can also use functions that output text inside the second argument, which will output the same text as Bart mentioned..
Code:
&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.
#7

[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.
#8

[eluser]TwoConnect[/eluser]
Personally, I stay away from the anchor tag. It makes things 10 times more complicated in my opinion
#9

[eluser]techgnome[/eluser]
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.

-tg




Theme © iAndrew 2016 - Forum software by © MyBB