SID-02202: INCLUDE with a character limit
| Status: |
Answered |
TWiki version: |
6.0.0 |
Perl version: |
5.18 |
| Category: |
CategoryRendering |
Server OS: |
Ubuntu 14.04 |
Last update: |
9 years ago |
Hi,
I am using INCLUDE in the format="..." section of a formatted search. The INCLUDE is including a specific section of the toplc (not the whole topic). I would like to limit the number of characters that are included, and add a link to the topic to see the full text.
I don't believe I can do this with the formatted search $summary() variable, as this would act on the entire topic. What I really need is a way to say 'INCLUDE section="Bio" limit="200"' can someone suggest an approach for this?
Thanks a lot,
Steve.
--
Steve Jones - 2016-05-23
Discussion and Answer
You can apply a
pattern="..." instead of
section="..." to limit the number of characters.
Untested example for an 80 character summary, assuming you have a level 2 heading
---++ Bio:
pattern=".*?\-\-\-*\+\+* *Bio\n+(.{80}).*"
Alternatively use a SEARCH with a
$pattern(...)
Details at
VarINCLUDE,
RegularExpressions,
VarSEARCH,
FormattedSearch.
--
Peter Thoeny - 2016-05-24
Hi Peter,
Thank you for your reply.
This works as you describe, but if the text in the 'Bio' section is less than 80 characters, unwanted text gets included (text beyond the end of the 'section').
This is why I wanted to use a named section - so that just the text in this section can be INCLUDEd. We don't know how many characters will be in there, but if there are more than 80, we should truncate. If there are less than 80, we should stop at the end of the section.
Is there a way to specify the pattern so that only text within the section/endsection is rendered?
I wasn't aware of the INCLUDE with pattern syntax, so thanks for pointing it out to me, it will be generally useful.
Steve.
--
Steve Jones - 2016-05-24
You could wrap the INCLUDE in a CALCULATE to strip off unwanted characters at the end.
Or better, use a positive lookahead to stop where you want. Untested example that stops at 80 chars or the next heading, whichever comes first:
pattern=".*?\-\-\-*\+\+* *Bio\n+((.{1,80})(?=\-\-\-*\+)|.{80}).*"
More at
TWikiPresentation2015x10x03.
But in any case, instead of trying to parse text from free form content that is at the mercy of the users, I think it is better to use
TWikiForms to store structured content. That is much safer (less chance of users inadvertently messing up content) and much easier to get data for reports. More at
How to Create a TWiki Application
--
Peter Thoeny - 2016-05-24
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.