Skip to content

Instantly share code, notes, and snippets.

@imuhammadshoaib
Last active November 20, 2022 10:46
Show Gist options
  • Save imuhammadshoaib/84881416f91ec47f7ac9ecfdc4a8b7de to your computer and use it in GitHub Desktop.
Save imuhammadshoaib/84881416f91ec47f7ac9ecfdc4a8b7de to your computer and use it in GitHub Desktop.
Add Read More & Read Less Button on Collection Description
{% if collection.description != blank %}
<div class="collection--description">
{% capture readmore %}
<div id="truncated">{{ collection.description | strip_html | truncatewords: 10, "... <a class='read-more-collection' data-no-instant>Read More</a>" }}</div>
<div id="fullDescription" style="display: none">{{ collection.description | append: " <a class='read-more-collection' data-no-instant>Read Less</a>" }}</div>
{% endcapture %}
{{ readmore }}
</div>
{% endif %}
<!-- Custom jQuery for colllection page -->
{% if template.name == 'collection' %}
<script type="text/javascript">
jQuery('.read-more-collection').click(function(){
if(jQuery('#truncated').is(":visible")){
jQuery('#truncated').hide();
jQuery('#fullDescription').show();
}
else{
jQuery('#truncated').show();
jQuery('#fullDescription').hide();
}
});
</script>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment