![]() |
anchor tags - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: anchor tags (/showthread.php?tid=43431) |
anchor tags - El Forum - 07-11-2011 [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? anchor tags - El Forum - 07-11-2011 [eluser]tintamarre[/eluser] Hello, I think this would do it! Code: echo anchor('home',img('images/img.png')); T. anchor tags - El Forum - 07-11-2011 [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 :-) anchor tags - El Forum - 07-12-2011 [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" />'); anchor tags - El Forum - 07-12-2011 [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. anchor tags - El Forum - 07-12-2011 [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')); anchor tags - El Forum - 07-12-2011 [eluser]Perkin5[/eluser] I tried that but php threw a parsing error...? anchor tags - El Forum - 07-12-2011 [eluser]cideveloper[/eluser] You could do this. Code: echo anchor('home',img(array('src' => 'images/img.png','id' => 'something','class' => 'somethingElse'))); anchor tags - El Forum - 07-12-2011 [eluser]Perkin5[/eluser] How cool is that? I love it and works like a charm. Thanks so much! |