brad
December 6, 2023, 4:41am
1
I have some truncated text and it works great!
{{optimized_full.data.comments[0].comment_text.trunc(400, true, ' ...')}}
I’d like to replace the ...
with a ‘Read More’ link. Is that possible? I know I can change the … to Read More but how can I add a link? Basically I just need it to open an offCanvas panel.
Hey @brad ,
I tried dmx-html and it works…
I created a <span>
element assigned to it the data-bs-toggle
& data-bs-target
and gave it a role="button"
<span class="text-danger" role="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasFilters">Read more</span>
Then I added a paragraph and set its dmx-html to trunc(nn, ‘true’, ‘…’) + the span that triggers the offCanvas
<p class="" dmx-html="srvc_prodList.data.qr_Prod_List.data[0].prd_Name.trunc(30, 'true', '...')+'<span class="text-danger" role="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasFilters">Read more</span>'">Fancy display heading</p>
2 Likes
brad
December 6, 2023, 4:34pm
3
Thank you! I will give it a try today. Much appreciated.
1 Like
TMR
December 6, 2023, 4:40pm
4
Will this not work?
{{optimized_full.data.comments[0].comment_text.trunc(400, true, '')}}<a href="https://yoursite.com/page">Read more...</a>
brad
December 6, 2023, 4:44pm
5
Thanks Tom, yes, that would work. But I only want to show the ‘Read More’ link if the text is truncated.
TMR
December 6, 2023, 4:55pm
6
use dmx-show to only show the link if the text is a greater length than 400.
I cant get to my machine right now so cant write it for you
1 Like
brad
December 6, 2023, 4:56pm
7
Interesting idea. I will give it a try.
TMR
December 6, 2023, 7:34pm
8
This should work for you:
<a href="https:yourlink.com" dmx-show="(optimized_full.data.comments[0].comment_text.length() > 400)">... read more</a>
1 Like
brad
December 6, 2023, 10:27pm
9
Thanks for pointing me in the right direction guys (@TMR and @famousmag ) Works like a charm.
{{optimized_full.data.comments[0].comment_text.trunc(400, true, ' ...')}} <span dmx-show="optimized_full.data.comments[0].comment_text.length()>=400"><a href="javascript:void(0);" dmx-on:click="offcanvasCommentHistory.show()">more</a></span>
2 Likes