Hello,
I am willing to create a page with several expandable text boxes with read more buttons. The texts are static. So far, I managed to create one with the Corvid tutorial , but I don’t know where I should add the code for the other text boxes and buttons without disturbing the first one. I created the second text (text55), the second button (button2) and added the code to control it, but I am not sure of where to put the code controlling the second text.
I am very new at this, so thank you for your help!
For now, the code for the page is:
$w.onReady( function () {
//TODO: write your page related code here…
// how many characters to include in the shortened version
const shortTextLength = 900;
// read the full text and store it in the fullText variable
fullText = $w(“#text53”).text;
// grab the number of characters defined in shortTextLength and store them in the shortText variable
shortText = fullText.substr(0, shortTextLength) + “…”;
// set the contents of the text element to be the short text
$w(“#text53”).text = shortText;
// how many characters to include in the shortened version
// read the full text and store it in the fullText variable
});
let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text
export function button1_click(event) {
// check the contents of the text element
if ($w(“#text53”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text53”).text = fullText;
$w(“#button1”).label = “Réduire”;
} else {
// if currently displaying full text, display the short text
$w(“#text53”).text = shortText;
$w(“#button1”).label = “Lire la suite”;
}
}
export function button2_click(event) {
//Add your code for this event here:
// check the contents of the text element
if ($w(“#text55”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text55”).text = fullText;
$w(“#button2”).label = “Réduire”;
} else {
// if currently displaying full text, display the short text
$w(“#text55”).text = shortText;
$w(“#button2”).label = “Lire la suite”;
}
}