Hi,
I’m using the marketingmessages and my client doesnt want to fill in the “short message” area for a summary but instead wants the first X amount of characters and a “read more” button.
My thought process was to add a field to my data definition and use “this.content.length().islowerequal(150)” but this doesnt slice off the message, instead only shows messages that have 150 characters or less. This way the front-ender can just use that message to display the summary.
Does sombody have an idea how to split/select only the first 150 characters for example?
Hi Miroslav,
That’s definitly the right way of thinking! But I fail at the last step and I can’t really understand why, maybe you have some idea? To me it looks good, maybe you see the issue?
Judging by the config i see (of course i could be wrong as i don’t know the data model you are dealing with), i think you want to return a single string, that is a text field on some record, so you need to change the Boolean:if to string:if(…), so your expression should be like
string:if( <-- I am returning a string
content.length().isgreaterequal(150), <--- condition
content.substring(0,150), <-- if condition is true
content <-- if condition is false
)
Hi Miroslav,
Thank you so much for the explanation. So first you tell the system what kind of datatype I expect to return and afterwards I can make the expression, that clears up so much!
The explanation was very clear!
Yes, that is if you use static functions (in this case IF is a static data function)
Of course, your expression could’ve been like:
“content.substring(0,150)” - if you type the expression like that, then the field would always return a string of length 150 characters.
With what we set-up above, now you return a substring if its larger then certain value, else the full one.
Depending on your use case - for example if i understood correctly, you want to show something like “Some content… See more…” that expands to the full text. So i can imagine your front-end developer could also make use of the following setup for your data definition - you could have 2 fields:
-short_content - string -content.substring(0,150)
-full_content - string - content
Maybe even a boolean field:
-has_really_long_content - content.length().isgreater(150) (the isgreater
evaluates to a boolean, as you saw above)
Now in the same data definition result you have both results which your front-end developer can utilise further…
But i leave the further setup to your imagination
To find out more about expressions you can also refer to this Wiki: