Hier das vollständige Template "block_searchable.html5":
PHP-Code:
<?php
// Compare the CSS definition with a pattern and set the results as HTML Data attributes
$strDelimiter = "DATA-";
$strPattern = '/'.$strDelimiter.'(.+?)\b/i';
$strDataAttr = "data-category";
$strCSS = $this->class; // default CSS output
// only if pattern matches
if ( substr_count($strCSS, $strDelimiter) > 0 ) {
// find all substrings between pattern in string
preg_match_all($strPattern, $strCSS, $arrMatches, PREG_PATTERN_ORDER, 0);
for( $i = 0; $i <= count($arrMatches); $i++) {
// cleanup full matches ( incl. delimiter ) from orginal CSS string
$strCSS = str_replace($arrMatches[0][$i], "", $strCSS);
// get matched values only
$arrMatchedValues[] = $arrMatches[1][$i];
}
// complete data attribute
$strData = $strDataAttr.'="'.rtrim(implode(", ", $arrMatchedValues), ", ").'"';
}
?>
<div class="<?= $strCSS ?> block"<?= $strData ?><?= $this->cssID ?><?php if ($this->style): ?> style="<?= $this->style ?>"<?php endif; ?>>
<?php $this->block('headline'); ?>
<?php if ($this->headline): ?>
<<?= $this->hl ?>><?= $this->headline ?></<?= $this->hl ?>>
<?php endif; ?>
<?php $this->endblock(); ?>
<?php $this->block('content'); ?>
<?php $this->endblock(); ?>
</div>
Bei Angabe der CSS Klasse(n) von z.B.: "filter-item DATA-category1 DATA-category2" in einem Inhaltselement "Text" erhält man dann:
Code:
...
<div class="ce_text filter-item first last block" data-category="category1, category2" id="myID">
...