• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using anchor around an image tag

[eluser]Eric Cope[/eluser]
Hello, I am trying to create the following code:
<a href="some/url"><img src="some/img.jpg"></a>

I am trying to use:
anchor("some/url","<img src='http://url/to/photo'>");

It produces odd undesired results. It is actually printing the text from a previous anchor call. Here is what it produces:

<a href="correct/url" <img src='current/img/src/path'>>link text from previous anchor use</a>

notice the redundant ">"?

It looks like it is redisplaying the old title. This does not sound correct. Any ideas or tips/tricks?

[eluser]Armchair Samurai[/eluser]
See this thread.

[eluser]Eric Cope[/eluser]
Thanks, that worked. What is it about the 'attribute="here"' that makes that work?

[eluser]Armchair Samurai[/eluser]
When CI parses the anchor function it automatically includes the title attribute by default, which is the same as the text. So when you try something like this:
&lt;?=anchor('path/here', '<img src="/path/to/image" alt="" />');?&gt;
CI uses &lt;img src="/path/to/image" alt="" /&gt; as the title, which causes the issues. The output would be:
<a href="path/here" title="<img src="/path/to/image" alt="" />"><img src="/path/to/image" alt="" /></a>
As you can see, not only it the title non-sensical, with all the double quotes in there it's a mess. Hence, adding the third parameter overrides the default inclusion of the title attribute. Reversing the quotes will make things work without the third parameter, but you still end up with a crap title attribute:
// input
&lt;?=anchor('path/here', "<img src='/path/to/image' alt='' />");?&gt;

&lt;!-- output --&gt;
<a href="path/here" title="<img src='/path/to/image' alt='' />"><img src='/path/to/image' alt='' /></a>

IMHO it's easier to just use HTML and use site_url() if you're worried about CI URIs.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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