[TYPO3-ttnews] Display teaser even when there is a subtitle
Georg Rehfeld
rehfeld at georg-rehfeld.de
Fri Feb 1 08:09:07 CET 2008
Hi Julien, all,
this probably comes much too late for you, Julien. But just for the
archives and because I needed the same functionality ...
Julien P. wrote:
> So I created a news with a title, a subtitle and a text. But when I display
> the news in list form, the title and subtitle are displayed. I know this is
> the normal behaviour.
>
> But is there a way to display the teaser as well? The teaser for now is
> displayed only when there is no subtitle. Moreover ...
The tt_news standard TS for the subheader/title in LIST is:
plugin.tt_news.displayList {
subheader_stdWrap {
# data comes from field 'short' by default,
# if that is empty use field 'bodytext' instead
ifEmpty.field = bodytext
# strip either field from any HTML
stripHtml = 1
# crop after at most 230 chars on whitespace, append ...
crop = 230 | ... | 1
}
}
So the subheader (short) takes precedence by code inside the tt_news
plugin ... but as you see, it can be substituted. To have both fields
shown you can use the stdWrap feature 'cObject' e.g. as follows.
Please note, that by default the generated subheader, though first
stripped from all HTML, finally is wrapped into the usual
<p class="bodytext"></p> by other TS. So in the following we only
format with CSS inline elements, because block elements (e.g. div/h4)
ain't allowed inside of <p>.
plugin.tt_news.displayList {
# clear default settings ...
subheader_stdWrap >
# ... we do it from scratch
subheader_stdWrap {
# note, that the current record is the news record just processed,
# so we can access any field from it.
# Let's have a stdWrap.cObject. This clears any default content.
# We choose a COA, as we wanna combine more than one field.
cObject = COA
cObject {
10 = TEXT
10 {
# first we get the 'short' aka subheader ...
field = short
# ... and remove any whitespace around it
trim = 1
# if 'short' now is empty, we don't apply the following
required = 1
# strip off any formatting (e.g. block elements) ...
stripHtml = 1
# ... and reformat it. We use a span.class here, so that
# we can format to our liking with a central stylesheet, e.g.
# span.news-list-subheader {
# display: block;
# margin: 0 0 5px 0;
# font-weight: bold;
# font-style: italic;
# text-decoration: underline;
# }
wrap = <span class="news-list-subheader">|</span>
# or format the old way alternatively
// wrap = <strong><em>|</em></strong><br />
# note, that we don't crop ... in our case the 'short' field
# really is short: something suitable for a <h3> in SINGLE view!
}
# at this point we either have nothing or a subheader content,
# e.g.: '<strong><em>This is a Subheader</em></strong><br />'.
20 = TEXT
20 {
# now we get the bodytext
field = bodytext
# just strip off any formatting
stripHtml = 1
# and crop it to max 300 chars
crop = 300 | ... | 1
}
# here we have both fields concatenated.
# If you want, you could apply further stdWrap processing for the
# whole string
// append = TEXT
// append {
// data = register:newsMoreLink
// wrap = <span class=”news-list-more”>|</span>
// }
}
}
}
See, tt_news is very flexible, because almost anything in it is cleverly
choosen to just derive from TYPO3 base features, combining these to a
wholly new thing.
And amoung the TYPO3 base features is TS (TypoScript). Especially
the 'stdWrap' function (including the getText datatype).
Please read the TSref once, to notice it. A second time to grasp a
little bit of it. And many more times, to be able to manage your TS.
Best regards,
Georg
--
___ ___
| + | |__ Georg Rehfeld Woltmanstr. 12 20097 Hamburg
|_|_\ |___ rehfeld at georg-rehfeld.de +49 (40) 23 53 27 10
More information about the TYPO3-project-tt-news
mailing list