[英]Add html data attribute to Joomla module
有時有必要向joomla模塊添加數據屬性,例如,如果您想使用wow.js並想要延遲事件,則必須將data-wow-delay ='2s'添加到模塊div中。 目前,無法在joomla框架內執行此操作
我有一個解決方案,有點花錢,但可以完成工作。 它使用模塊管理器“高級”選項卡下的“標題類”字段。
在您的模板覆蓋目錄templates / yourtemplate / html中,您應該找到一個名為modules.php的文件。我有一個名為block的模塊樣式,該樣式在我的index.php文件中使用。
我對其進行了編輯,以查看hederclass變量,並查看其是否包含字符data-。 如果是這樣,我假設標題類實際上是一個數據屬性。 這是代碼。
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;
}
要使其工作,請在joomla模塊管理器中,打開要向其應用data屬性的模塊,單擊“高級”選項卡,然后在“ Header Class”字段中使用SINGLE QUOTES如下所示添加數據屬性
data-wow-delay='2s'
希望這可以幫助某人
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.