Adding a read more on my long product descriptions and making it full page width

Hi all

So I am wanting to add a read more to my long product descriptions. I am also wanting the product description to be full page width and keeping the style that i am using.I already am using this in a custom liquid section on my products:

{{ product.description }}

I am using the Ride theme.

Any help will be really appreciated

@ImStillLearning Here a quick idea how to do it.

NOTE: I haven’t tested this in an actual site.


   

     
{{ product.description | truncate:'205' }}...

     {{ product.description }}

     Read More
 
  

Thank you this worked!

Ok So I have been testing it in my duplicated theme and I have noticed that it will work on most products but then on some you click on read more and the whole description disappears.

@ImStillLearning HTML tags are treated as strings, so you should strip any HTML from truncated content. If you don’t strip HTML, then closing HTML tags can be removed, which can result in unexpected behavior.

Heres an updated version. NOTE that this solution will remove any HTML/styling from your description.


   

     
{{ product.description | strip_html | truncatewords:'50' }}...

     {{ product.description }}

     Read More
 
  

Another way to solve this issue is to create a custom meta field in the backend where you can insert the short description.
Follow this tutorial

and update the code to:


   

     
{{ product.metafields.custom.short_description }}...

     {{ product.description }}

     Read More
 
  

Hi @Leysam ,
This code works, however as you mentioned, its deleting all the style:

<div class="page-width">
   <div class="product-description">
     <div class="short">{{ product.description | strip_html | truncatewords:'50' }}...</div>
     <div class="long">{{ product.description }}</div>
     <div class="read-more-button">Read More</div> 
  </div>
</div>

<script>
const readMoreBtn = document.querySelector('.read-more-button');
const text = document.querySelector('.product-description');
readMoreBtn.addEventListener('click',(e)=>{
    text.classList.toggle('more');

    if (text.classList.contains('more')) readMoreBtn.innerHTML = 'Read Less';
    else  readMoreBtn.innerHTML = 'Read More';
})
</script>
<style>
.product-description .long {
  display: none;
}
.product-description.more .long {
  display: block;
}
.product-description.more .short{
  display: none;
}
</style>

I was trying to use meta fields, but its not working :disappointed_face: Is there any other solution which can save the styling of description?

Thank you!