Mar. 1., 2008

Change Typoscript values at parsetime

By Steffen Müller. Licensed under the Creative Commons License

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.

--> Back to the list of articles

Tags: TypoScript, TYPO3

License

Licensed under creative commonsThis article is licensed under the Creative Commons License CC BY-SA 3.0. You are free to share (copy, distribute and transmit) and to remix (to adapt) the work under the following conditions:

  • You must attribute the work by mentioning the name of the author (Steffen Müller) and setting a link back to the original article using its URL.
  • If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

Comments

  1. Phil wrote on July 27, 2010 at 20:18

    Sample usage of replaceString:

    somevalue := replaceString(oldstring|newstring)

  2. TypoConsult wrote on November 17, 2010 at 23:59

    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


Leave a comment:

This page uses static caches. Make sure you reload the page in your browser after posting a comment.

(will not be published)

CAPTCHA image for SPAM prevention Click here for audio version of the word to enter.

If you can't read the captcha word, please click to load a new image.
(You need Javascript turned on. Otherwise press the submit button and wait until the page has reloaded.)