php - JEA 设施布局添加自定义 css 样式

标签 php html css joomla

我正在查看代码,只是不明白如何将自定义 CSS 类添加到 ul 标记?

  <?php if (!empty($this->row->amenities)): ?>
  <h3><?php echo JText::_('COM_JEA_AMENITIES')?> :</h3>
  <?php echo JHtml::_('amenities.bindList', $this->row->amenities, 'ul') ?>
  <?php endif ?>

生成:

<h3>Amenities</h3>
<ul>
 <li></li>
 <li></li>
 <li></li>
 etc.
</ul>

我需要:

<h3>Amenities</h3>
<ul class="check">
 <li></li>
 <li></li>
 <li></li>
 etc.
</ul>

我敢肯定,它应该很简单。

最佳答案

函数的来源是-

static public function bindList($value=0, $format='raw')
{
    if (is_string($value) && !empty($value)) {
        $ids = explode('-' , $value);
    } elseif (empty($value)) {
        $ids = array();
    } else {
        JArrayHelper::toInteger($value);
        $ids = $value;
    }

    $html = '';
    $amenities = self::getAmenities();
    $items = array();

    foreach ($amenities as $row) {
        if (in_array($row->id, $ids)) {
            if ($format == 'ul'){
                $items[] = "<li>{$row->value}</li>\n";
            } else {
                $items[] = $row->value;
            }

        }
    }

    if ($format == 'ul'){
        $html = "<ul>\n" . implode("\n", $items) . "</ul>\n";
    } else {
        $html = implode(', ', $items);
    }

    return $html;

}

根据函数的来源,我看到的方式是替换 '<ul>''<ul class="check">'

<?php 
$html = JHtml::_('amenities.bindList', $this->row->amenities, 'ul');
echo str_replace('<ul>','<ul class="check">',$html);    
?>

或者您可以调用getAmenities函数并循环遍历结果并创建您自己的 ul 和 li。

希望这对您有所帮助。

关于php - JEA 设施布局添加自定义 css 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26848338/

相关文章:

php - CakePHP 定义常量

php - Javascript/Cookie 是启用还是禁用?

javascript - jQuery:<ul> 中的动态插入将无法正常工作

javascript - 如何有选择地将脚本应用于元素?

css - jhipster cloud foundry 图片

html - 如何在CSS中为动画背景图像设置原始图像

php - jQuery 使用 PHP 脚本更新 Div

php - 为什么冒泡排序从 C 移植到 PHP 不起作用?

html - 如何将 figcaption 放在图像顶部

html - 多个全尺寸背景图像