【问题标题】:JEA amenities layout add custom css styleJEA 便利设施布局添加自定义 CSS 样式
【发布时间】:2015-01-07 00:35:32
【问题描述】:

我正在查看代码,只是不明白如何将自定义 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>

我确定,应该很简单。

【问题讨论】:

    标签: php html css joomla


    【解决方案1】:

    函数的来源是-

    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;
    
    }
    

    根据函数的来源,我可以看到将'&lt;ul&gt;' 替换为'&lt;ul class="check"&gt;'

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

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

    希望这会有所帮助。

    【讨论】:

    • 谢谢,您的示例运行良好。愚蠢的问题,你从哪里找到函数的来源?
    • @nox:Good to know.You can find the class inside -> Joomla folder->components\com_jea\helpers\html\amenities.php
    猜你喜欢
    • 2014-08-29
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    相关资源
    最近更新 更多