• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
anchor tags

#1
[eluser]Perkin5[/eluser]
I've come across an interesting little puzzle. I want to put in an anchor tag using the url helper like this, largely because it automatically gets the link path right:

Code:
echo anchor('home','images/img.png');

but of course that only puts in 'images/img.png' as text. What I want to do is to be able to click on the image so I want to use the html helper code like:

Code:
echo img('images/img.png');

How can I embed one within another, or otherwise achieve the result?

#2
[eluser]tintamarre[/eluser]
Hello,

I think this would do it!

Code:
echo anchor('home',img('images/img.png'));

T.

#3
[eluser]Perkin5[/eluser]
Brilliant - thank you so much. Now I see it I don't know why I didn't try that - I tried lots of other ways.

Anyway, problem solved :-)

#4
[eluser]boltsabre[/eluser]
Or of course you could pass it the whole image tag if you need to apply styling or anything else (perhaps an id for some JS).

Code:
echo anchor('home', '<img src="images/img.png" id="topNavImage" style="height:20px" />');

// or if you need php in there as well (ie, image path - which is best to do this way incase
// you later move your files around and loose your path to your image folder, this way the path cannot be broken.

echo anchor('home','<img src="'.base_url().'images/img.png" id="topNavImage" style="height:20px" />');

#5
[eluser]Perkin5[/eluser]
Or you could presumably do:

Code:
echo anchor('home',img('images/img.png'),'id="something",class="somethingElse"');

Ah no - that would apply the attributes to the anchor I guess.

I get your point and thanks a lot for the insight.

#6
[eluser]boltsabre[/eluser]
ah sorry, I just re-read your initial post, the whole idea was to make use of the html helper in the first place! But it looks like you got what you needed from tintamarres answer. However, I mite have a play around with your code tonight when I get home from work, you could be onto something there, there must be a way to make it work! Maybe this...?

Code:
echo anchor('home',img('images/img.png',id='something',class='somethingElse'));

#7
[eluser]Perkin5[/eluser]
I tried that but php threw a parsing error...?

#8
[eluser]cideveloper[/eluser]
You could do this.

Code:
echo anchor('home',img(array('src' => 'images/img.png','id' => 'something','class' => 'somethingElse')));

#9
[eluser]Perkin5[/eluser]
How cool is that? I love it and works like a charm.

Thanks so much!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.