joomlajoomla3.0bootstrap-sassjhtmlarea

How to add a bootstrap class to JHtml in Joomla


I am using following piece of code to display an image which I am fetching from gravatar.com, so I want to use a bootstrap CSS class to make it more attractive. As soon as I add the style rather than showing the image it shows me the link to the image, when I redirect to the link I am able to see the image. Why I am getting this?

$html[] = JHtml::_('image', $grav_url,'class="img-circle"', JText::_('PLG_CONTENT_AVATAR'), null, true)

Here $grav_url is the url I am getting for the image and img-circle is the bootstrap class that I want to use.


Solution

  • I believe the library you're using is here:

    https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/html/html.php#L567

    So you can see in the parameter list that there is a param for $attribs which is of the type array. The other thing is there is an additional $alt param you have to pass which might be your jtext just out of order. To pass that to the method you would do:

    $html[] = JHtml::_('image', $grav_url, JText::_('PLG_CONTENT_AVATAR'), array('class'=>'img-circle'), true)
    

    Or you could build the array outside the method as a variable:

    $attribs = array();
    $attribs['class'] = 'img-circle'; // I think this should work? haven't tested though.
    
    $html[] = JHtml::_('image', $grav_url, JText::_('PLG_CONTENT_AVATAR'), $attribs, true)