Search code examples
laravelimagelaravel-4anchor

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.??


Solution

  • 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>"