Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Image link with HTML Helper

I'm trying to create an image link with the HTML helper of Laravel 4. But it seems that isn't really working. I have this line of code

{{ HTML::link("#", HTML::image("img/logo.png", "Logo") ) }}

But that just outputs a strin like this:

<img src="http://localhost/worker/public/img/logo" alt="Logo">

How come.??

like image 927
mXX Avatar asked Sep 25 '13 14:09

mXX


People also ask

How do you make an image a link in HTML?

To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image. With that, also add the height and width.

What is HTML helper method?

An HTML Helper is just a method that returns a HTML string. The string can represent any type of content that you want. For example, you can use HTML Helpers to render standard HTML tags like HTML <input>, <button> and <img> tags etc.


2 Answers

I think it's overkill for no reason. I would do:

<a href="#"><img src={{asset('img/logo.png')}} alt="Logo"></a>

If I then need a dynamic link in place of the #, I would do:

<a href="{{URL::to('/')}}"><img src={{asset('img/logo.png')}} alt="Logo"></a>

Try to use html as much as you can.

like image 164
kJamesy Avatar answered Oct 31 '22 05:10

kJamesy


You probably will have to:

<a href="#">{{ HTML::image("img/logo.png", "Logo") }}</a>

Because, link() uses entities to escape the title:

public function link($url, $title = null, $attributes = array(), $secure = null)
{
    $url = $this->url->to($url, array(), $secure);

    if (is_null($title) or $title === false) $title = $url;

    return '<a href="'.$url.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
}

Producing this source code:

"<a href="#">&lt;img src=&quot;http://localhost/img/logo.png&quot; alt=&quot;Logo&quot;&gt;</a>"
like image 26
Antonio Carlos Ribeiro Avatar answered Oct 31 '22 03:10

Antonio Carlos Ribeiro