feat(extra-features): Add readMore smarty helper; clarify comments

This commit is contained in:
2025-12-10 10:16:42 +01:00
parent 28f8794e16
commit 797bedf573

View File

@ -190,6 +190,15 @@ class SmartyHelperFunctions
return $content; return $content;
} }
/* CUSTOM ADDITIONS BELOW */
public static function isBright($hexColor) public static function isBright($hexColor)
{ {
$calculator = new ColorBrightnessCalculator(); $calculator = new ColorBrightnessCalculator();
@ -198,7 +207,7 @@ class SmartyHelperFunctions
/* Helper to display SVG icons stored in themes/falcon/_dev/img/icons/ /* Helper to display SVG icons stored in themes/falcon/_dev/img/icons/
Registered under public_html/config/smartyfront.config.inc.php registered under public_html/modules/is_themecore/src/Hook/Smarty.php
Usage examples in a TPL file: Usage examples in a TPL file:
@ -248,6 +257,8 @@ class SmartyHelperFunctions
} }
/* Helper to split the price into euros and cents to make it more stylish /* Helper to split the price into euros and cents to make it more stylish
registered under public_html/modules/is_themecore/src/Hook/Smarty.php
Usage examples in a TPL file: Usage examples in a TPL file:
{price_split price=$product.price} {price_split price=$product.price}
@ -269,5 +280,64 @@ class SmartyHelperFunctions
} }
} }
} }
/* Helper to add a read more function to text
registered under public_html/modules/is_themecore/src/Hook/Smarty.php
Use this JS in public_html/themes/falcon/_dev/js/theme/custom.js to handle the read more link:
// Read more buttons
$(".read-more-text").on("click", function (event) {
event.preventDefault();
const $link = $(this);
const $container = $link.closest(".read-more");
$container.find(".truncated-after").toggleClass("d-none");
$container.find(".ellipsis").toggleClass("d-none");
$link.find(".read-more").toggleClass("d-none");
$link.find(".read-less").toggleClass("d-none");
});
Usage example in a TPL file:
{read_more text=$product.description_short maxLength=10 readMoreText={l s='Read more' d='Shop.Theme.Catalog'} readLessText={l s='Read less' d='Shop.Theme.Catalog'}}
*/
public static function readMore($params){
if (empty($params['text'])) {
return '';
}
$text = $params['text'];
$maxLength = isset($params['maxLength']) ? (int)$params['maxLength'] : 200;
$readMoreText = isset($params['readMoreText']) ? $params['readMoreText'] : 'Read more';
$readLessText = isset($params['readLessText']) ? $params['readLessText'] : 'Read less';
// Strip and count text length
$text_stripped = strip_tags($text);
if (strlen($text_stripped) <= $maxLength) {
return $text;
}
// Split text and add read more link
$truncatedBefore = substr($text_stripped, 0, $maxLength);
$lastSpace = strrpos($truncatedBefore, ' ');
if ($lastSpace !== false) {
$truncatedBefore = substr($truncatedBefore, 0, $lastSpace);
$truncatedAfter = substr($text_stripped, $lastSpace);
} else {
$truncatedAfter = substr($text_stripped, $maxLength);
}
return
'<div class="read-more">'.
'<span class="truncated-before">' . $truncatedBefore . '</span>' .
'<span class="ellipsis">...</span>' .
'<span class="truncated-after d-none">' . $truncatedAfter . '</span>' .
'<a class="read-more-text d-flex" href="#">' .
'<span class="read-more">' . $readMoreText . '</span>' .
'<span class="read-less d-none">' . $readLessText . '</span>' .
'</a>'.
'</div>';
}
} }