Last active
July 18, 2023 08:36
-
-
Save AndreaRivadossi/1d3115405c02a816cbf26cee5e1e2673 to your computer and use it in GitHub Desktop.
read more/less, alpine js, for magento 2 hyva themes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="mb-4 leading-relaxed product-description prose" | |
x-data="{ isCollapsed: false, maxLength: 420, originalContent: '', content: '' }" | |
x-init="originalContent = $el.firstElementChild.textContent.trim(); content = originalContent.slice(0, maxLength) + '...'"> | |
<p x-text="isCollapsed ? originalContent : content" class="m-0"> | |
<?= /* @noEscape */ $shortDescription ?> | |
</p> | |
<a class="inline-flex font-black underline uppercase cursor-pointer text-sm hover:text-orange" | |
@click="isCollapsed = !isCollapsed" | |
x-show="originalContent.length > maxLength" | |
x-text="isCollapsed ? '<?= __('- Read less') ?>' : '<?= __('+ Read more') ?>'"> | |
</a> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment