How to add a bootstrap class to JHtml in Joomla

独自空忆成欢 提交于 2019-12-11 13:49:30

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/21825763/how-to-add-a-bootstrap-class-to-jhtml-in-joomla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!