简体   繁体   English

将HTML数据属性添加到Joomla模块

[英]Add html data attribute to Joomla module

Sometimes it is necessary to add a data attribute to a joomla module, for instance if you want to use wow.js and want a delayed event you have to add data-wow-delay='2s' to the module div. 有时有必要向joomla模块添加数据属性,例如,如果您想使用wow.js并想要延迟事件,则必须将data-wow-delay ='2s'添加到模块div中。 At present there is no way to do this within the joomla framework 目前,无法在joomla框架内执行此操作

I have a solution which is a bit of a fudge, but gets the job done. 我有一个解决方案,有点花钱,但可以完成工作。 It uses the 'header class' field under the advanced tab of the module manager. 它使用模块管理器“高级”选项卡下的“标题类”字段。

in your template override directory templates/yourtemplate/html you should find a file called modules.php I have a module style called block which I use in my index.php file. 在您的模板覆盖目录templates / yourtemplate / html中,您应该找到一个名为modules.php的文件。我有一个名为block的模块样式,该样式在我的index.php文件中使用。

I edited it to look at the hederclass variable and see whether it contains the characters data-. 我对其进行了编辑,以查看hederclass变量,并查看其是否包含字符data-。 If so I'm assuming that the header class is actually a data attribute. 如果是这样,我假设标题类实际上是一个数据属性。 here is the code. 这是代码。

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

To make it work, in joomla module manager, open the module you want to apply the data attribute to, click on the 'advanced' tab and in the Header Class field add your data attribute using SINGLE QUOTES as follows 要使其工作,请在joomla模块管理器中,打开要向其应用data属性的模块,单击“高级”选项卡,然后在“ Header Class”字段中使用SINGLE QUOTES如下所示添加数据属性

data-wow-delay='2s'

Hope this helps someone 希望这可以帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM