stmllr.net

Change Typoscript values at parsetime

by on stmllr.net

Typoscript properties in the CONFIG section are usually defined once and at a certain point. But what if you have defined the value of a property at some place and like to add another one later in the parsing process?

Example

A prominent example is config.linkVars. In most cases, it's used to append the global language parameter L to typolinks:

config.linkVars = L

However, if you need to append another value to that property using a basis template or an extension template, you can do this with := addToList():

config.linkVars := addToList(print)

Parsing both properties will have the same result as:

config.linkVars = L, print

List of functions

It's so easy, isn't it? Mind the := operator as a placeholder for the parser to process the function. The "TypoScript Syntax and In-depth Study" docs reveal the following list of functions which can be used here. There's even a hook to use your own functions.

prependString()

... adds a string before the existing one.

appendString()

... adds a string after the existing one.

removeString()

... removes a string from the existing one. str_replace() is used here.

replaceString()

... replaces an existing string with a new one. str_replace() is used here,with the pipe symbol | as a divider.

addToList()

... appends values to a comma separated list. The list will neither be sorted nor distinct. Multiple values are given as a comma separated list.

removeFromList()

... removes values from a comma separated list. Multiple values are given as a comma separated list.

Tags

Comments

  1. Phil

    Sample usage of replaceString:

    somevalue := replaceString(oldstring|newstring)

  2. TypoConsult

    A quick example:

    lib.footer = COA
    lib.footer {
    wrap = Copyright ###year### typoconsult.dk
    wrap := replaceString(###year###||)

    10 = TEXT
    10 {
    wrap = |
    data = date:U
    strftime =%Y
    }
    }

    Kind regards
    TypoConsult