Fedir RYKHTIK
Fedir RYKHTIK

Reputation: 9974

TypoScript : make transversal MySQL query without use of `pidInList` option

As it's mentioned on TYPO3 wiki, we could make a query with TypoScript :

page.60 = CONTENT
page.60 {
   table = tt_content
   select {
       pidInList = 73
       where = header != ###whatever###
       orderBy = ###sortfield###
       markers {
         whatever.data = GP:first
         sortfield.value = sor
         sortfield.wrap = |ting
       }
   }
}

What is inconvenient for me, it's parameter pidInList. Even when we didn't use it, the script substitute current page id with pid in the query. Is there a way to make it simpliler, for example, to realize such simple query :

select title from pages where uid=100;

What be the simpliest TypoScript equivalent ?

Upvotes: 2

Views: 3135

Answers (2)

Mateng
Mateng

Reputation: 3734

For your example:

SELECT title FROM pages WHERE uid=100;

the simplest TypoScript equivalent is:

page.60 = RECORDS
page.60 {
    tables = pages
    source = 100
    dontCheckPid  = 1
    conf.pages = TEXT
    conf.pages.field = title
    }

Note that the source parameter is mandatory. For more flexible queries I'd recommend writing a quick userFunc.

Upvotes: 1

tmt
tmt

Reputation: 8614

As far as I know pidInList is required. The workaround is to set it to "0" and use the recursive attribute.

page.60 = CONTENT
page.60 {
   table = tt_content
   select {
       pidInList = 0
       recursive = 99
       where = header != ###whatever###
       orderBy = ###sortfield###
       markers {
         whatever.data = GP:first
         sortfield.value = sor
         sortfield.wrap = |ting
       }
   }
}

NOTE: If you are worried about the performance impact and you are selecting records purely by their UIDs, consider using the RECORDS object instead.

Upvotes: 4

Related Questions