Replace shared content automatically by using parseFunc.short
Motivation
On a website, there are often text blocks or single words that occur in several places. In this case it is useful to store these texts at a central location along with an arbitrary short name. These short names can then be used as a kind of placeholder in content elements throughout the site and will be replaced automatically.
Example
On this website you can see, how those shortnames can be applied: The headings "Motivation", "Example", and "Best Practice" are actually the shortnames "MOTIVATION", "EXAMPLE", and "BEST_PRACTICE".
Just basic words are replaced here. But you can also replace URLs, whole text blocks or HTML tags (e.g. <img src> tags for images).
Best Practice
By storing the texts and their corresponding shortnames at a central location, it gets easy to modify the texts quickly. You could, for example, change the value of the shortname "EXAMPLE" to "case study" and this text would be replaced in all content elements that contain this placeholder. This is kind of a "search and replace" feature in TYPO3.
How and where to store the shortnames?
This is done by adding the parseFunc.short function (TEXT cObject) to the PAGE object (here: "page") in your TypoScript template:
# language 0: German (default) page.stdWrap.parseFunc.short { # simple text EXAMPLE = Beispiel # baseUrl of our website (Constant from CONSTANTS section) BASE_URL = {$baseUrl} # <a href> tag URL_PARTNER = <a href="http://www.partneragentur.de">Partneragentur</a> } # language 1: English [globalVar = GP:L=1] page.stdWrap.parseFunc.short { EXAMPLE = example BASE_URL = {$baseUrl} URL_PARTNER = <a href="http://www.partneragency.com">partner agency</a> } [global]
As you can see, various assignments are possible (simple text, TypoScript constants, HTML tags, etc.). Using TypoScript conditions, translations for several languages can be defined for the same shortnames.
Now let's see how this works in a text that contains the placeholders defined in the example above:
Original text with placeholders
This is an EXAMPLE for automatic replacement of placeholders using the parseFunc.short function: The baseUrl of our website is BASE_URL and this is a hyperlink to our URL_PARTNER.
Using the shortnames which were defined in our example above, this text will be changed in the following way:
Text parsed by parseFunc.short
This is an example for automatic replacement of placeholders using the parseFunc.short function: The baseUrl of our website is http://www.jochen-froehlich.de/ and this is a hyperlink to our <a href="http://www.partneragency.com">partner agency</a>.
Tip
To prevent accidental replacement of e.g. abbreviations, we recommend to assign a unique prefix to the placeholders. For example, we prepend the string "S_" (for "short") to each of our shortnames.
Read on
Be the first to comment this article!
Visitors found this page by searching for these keywords: