Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Theme.js: How to truncate Collection and Product descriptions AND titles on the same page (Venture)

Theme.js: How to truncate Collection and Product descriptions AND titles on the same page (Venture)

CluelessA
Excursionist
22 0 5

Hello, help please!

By following this solution:

https://community.shopify.com/c/shopify-design/collection-description-truncate-with-option-to-show-m...

 

I was able to successfully truncate EITHER the product description, or the collections description. I'm trying to do both (and later also the title). I believe the problem is on the theme.js file, at the very end of the code page I have copied this:

 

let read_more = document.getElementById('read-more')
let read_less = document.getElementById('read-less');
let truncated_description = document.getElementById('truncated-collection-description');
let full_description = document.getElementById('collection-description');

read_more.addEventListener('click', showHideDescription)
read_less.addEventListener('click', showHideDescription)

function showHideDescription(){
  let ID = this.id
  if(ID === "read-more"){
    truncated_description.style.display = "none";
    full_description.style.display = "block";
  }else {
    truncated_description.style.display = "block";
    full_description.style.display = "none";    
  }
}

 With this code, I can only write ('truncated-collection-description') OR ('truncated-product-description'), I don't know how to write both, I've tried writing ('truncated-collection-description','truncated-product-description') and ('truncated-collection-description'),('truncated-product-description'), I've also tried duplicating this code block, each block with "product" and "collection", nothing works.

 

Note this is on a test page, so I don't have this code live.

 

Thank you so much in advance if anyone knows the solution.

Replies 0 (0)