Php 向Joomla模块添加html数据属性

Php 向Joomla模块添加html数据属性,php,joomla,Php,Joomla,有时有必要向joomla模块添加一个数据属性,例如,如果你想使用wow.js并想要一个延迟事件,你必须将数据wow delay='2s'添加到模块div。目前在joomla框架内无法做到这一点我有一个解决方案,它有点模棱两可,但完成了任务。它使用模块管理器高级选项卡下的“header class”字段 在模板覆盖目录templates/yourtemplate/html中,您应该找到一个名为modules.php的文件 我在index.php文件中使用了一个名为block的模块样式 我编辑它是为

有时有必要向joomla模块添加一个数据属性,例如,如果你想使用wow.js并想要一个延迟事件,你必须将数据wow delay='2s'添加到模块div。目前在joomla框架内无法做到这一点

我有一个解决方案,它有点模棱两可,但完成了任务。它使用模块管理器高级选项卡下的“header class”字段

在模板覆盖目录templates/yourtemplate/html中,您应该找到一个名为modules.php的文件 我在index.php文件中使用了一个名为block的模块样式

我编辑它是为了查看hederclass变量,看看它是否包含字符数据-。如果是这样,我假设header类实际上是一个数据属性。 这是代码

function modChrome_block($module, &$params, &$attribs)
{

    // Temporarily store header class in variable
    $headerClass    = $params->get('header_class');
    $headerAttribute = '';  //define the variable for the attribute
    if ($headerClass !=''){
        if (stripos($headerClass,'data-') !== false) {  //check to see if the header class contains the characters 'data-'
            $headerAttribute = htmlspecialchars($headerClass);
            $headerClass = '';
        }else{
            $headerClass    =  ' class="' . htmlspecialchars($headerClass) . '"';
        }
    }

    if (!empty ($module->content)) : ?>
           <div class="block <?php if ($params->get('moduleclass_sfx')!='') : ?><?php echo $params->get('moduleclass_sfx'); ?><?php endif; ?>" <?PHP echo $headerAttribute; ?>>
            <div class="moduletable">               
                <?php if ($module->showtitle != 0) : ?>
            <div class="module-title">
                            <h3 <?PHP echo $headerClass; ?>><?php echo $module->title; ?></h3>
            </div>
                        <?php endif; ?>
                        <div class="module-content">
                            <?php echo $module->content; ?>
                        </div>
              </div>                
           </div>
    <?php endif;
}
希望这对别人有帮助

data-wow-delay='2s'