diff --git a/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php b/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php index 36399ee..218fedd 100644 --- a/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php +++ b/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php @@ -190,7 +190,16 @@ class SmartyHelperFunctions return $content; } - public static function isBright($hexColor) + + + + +/* CUSTOM ADDITIONS BELOW */ + + + + + public static function isBright($hexColor) { $calculator = new ColorBrightnessCalculator(); return $calculator->isBright($hexColor); @@ -198,7 +207,7 @@ class SmartyHelperFunctions /* 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: @@ -248,6 +257,8 @@ class SmartyHelperFunctions } /* 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: {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 + '
'. + '' . $truncatedBefore . '' . + '...' . + '' . $truncatedAfter . '' . + '' . + '' . $readMoreText . '' . + '' . $readLessText . '' . + ''. + '
'; + } }