Feeds:
RSS
Atom

I like playing with TypoScript. It is wonderful when unusual task is solved after some time of searching and thinking. It is like drawing a picture: need to have sense of art.

In this article I want to draw your attention to Opens external link in new windowthis post in mailing lists by Tomas Mrozek. Summary of the problem: there is a parameter in the URL that is UID of a record in a custom table. This table has a field that contains UID of page. Content should come from that page. Solution was to construct TypoScript that solves this problem. Here is final result:

subparts.MYMARKER.20 < styles.content.get
subparts.MYMARKER.20.select.pidInList.cObject = CONTENT
subparts.MYMARKER.20.select.pidInList.cObject {
  table = myTable
  select {
    pidInList = 123
    selectFields = myField
    andWhere.data = GPVar:myVariable
    andWhere.intval = 1
    andWhere.wrap = uid=|
  }
  renderObj = TEXT
  renderObj.field = myField
}

As you see, first we take standard "styles.content.get". It creates a content object that fetches content from the current page. Now we need to adjust it to fetch content from another page. This is simple: we need to change pidInList subproperty of its select property. But this is tricky because this property depends on the URL's parameter.

We use the fact that pidInList is Opens external link in new windowstdWrap. We use cObject property of stdWrap to generate page ID. We define it as CONTENT. This is unusual because CONTENT usually retrieves records for displaying them. Here we retrieve a value of the field named myField from table myTable. We use andWhere to set condition. andWhere is also stdWrap (simple where is not!) and we set its data property to the value of our variable.

Here I must give important note: it is possible to make SQL injection with such code unless you have that intval property set.

Then it is wrapped with rest of "where" condition. renderObj renders it as text.

This piece shows how TypoScriot can be used to achieve almost anything that you want. However, do not forget about security when you write such code.

Like it? Then bookmark it! digg.comdel.icio.usgoogle.comMyLink.deYahooMyWebTechnoratiFurllive.comnetscapeTagThatWebnews

Leave a Reply