in reply to Splitting long text for Template
I have an app where the shortened “preview” can be supplied by the article author or editor – so it might not be text from the beginning of the article. For me, that makes the preview a potential attribute of the article itself. (If there’s no supplied preview, I generate one by extracting text up to the first paragraph break after a length threshold.)
So the article has html and preview_as_html methods, and the template does something like:
[% IF article.has_preview %] [% article.preview_as_html %] <p class="readmore"><a href="[% article.uri %]">Read more…</a></p> [% ELSE %] [% article.html %] [% END %]
You could just as easily have the template output them both, with the full text hidden, and have your JS toggle between them.
This also shows how I handle the model/view distinction in this app. The article object that the template sees is considered “view support” code and is a wrapper around the object from the DB. I’m doing a conversion from MultiMarkdown → HTML inside the wrapper object. (Actually, it’s not quite as simple as that or I could do that in the template with the Template::Plugin::MultiMarkdown plugin.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Splitting long text for Template
by marto (Cardinal) on Feb 08, 2021 at 10:40 UTC | |
|
Re^2: Splitting long text for Template
by LanX (Saint) on Feb 08, 2021 at 14:48 UTC | |
by Radiola (Monk) on Feb 08, 2021 at 17:56 UTC | |
by LanX (Saint) on Feb 08, 2021 at 18:13 UTC | |
by Bod (Parson) on Feb 08, 2021 at 20:24 UTC | |
by bliako (Abbot) on Feb 08, 2021 at 20:46 UTC | |
by Bod (Parson) on Feb 08, 2021 at 21:10 UTC | |
| |
|
Re^2: Splitting long text for Template
by Bod (Parson) on Feb 08, 2021 at 17:45 UTC | |
by Radiola (Monk) on Feb 08, 2021 at 18:04 UTC |