如何在 Joomla 中向 JHtml 添加引导程序类 [英] How to add a bootstrap class to JHtml in Joomla

查看:20
本文介绍了如何在 Joomla 中向 JHtml 添加引导程序类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来显示我从 gravatar.com 获取的图像,因此我想使用引导 CSS 类使其更具吸引力.一旦我添加样式而不是显示图像,它就会向我显示图像的链接,当我重定向到链接时,我就可以看到图像.为什么我得到这个?

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)

这里 $grav_url 是我为图像获取的 url,img-circle 是我想要使用的引导程序类.

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

推荐答案

我相信您正在使用的库在这里:

I believe the library you're using is here:

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

因此您可以在参数列表中看到 $attribs 的参数是数组类型.另一件事是您必须传递一个额外的 $alt 参数,它可能是您的 jtext 乱序.要将其传递给您将执行的方法:

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)

这篇关于如何在 Joomla 中向 JHtml 添加引导程序类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆