0

I have an own DCE element and I want to show a random one on the start page.
When I select the CType via 10 = CONTENT and select, I must type a pidInList.
But I want a CE from the whole site, not from a specific uid.

How can iI disable this in the sql statement?

my current code:

        10 = CONTENT
        10 {
            table = tt_content
            select {
                selectFields = *, rand() as virt_rnd
                pidInList = *
                where = colPos=0 and CType=dce_ref
                max = 1
                orderBy = virt_rnd
                languageField = sys_language_uid
            }
Oliver Hader
  • 4,093
  • 1
  • 25
  • 47

2 Answers2

0

you could use:

  select {
    selectFields = *
    pidInList = root
    recursive = 10
    orderBy = rand()
    where = colPos=0 and CType=dce_ref
    max = 1
    languageField = sys_language_uid
  }

use the root page (uid = 0) and all pages 10 levels deep (or more if your pagetree is deeper)

Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
  • thanks, but this throws an Error: Unknown column 'rand()' in 'order clause' I remove the orderBy for the first, and the result is empty. With an incorrect sql i get the folowing sql statement from this: ````SELECT * FROM `tt_content` WHERE (`tt_content`.`uid` = 0) AND (colPos=0 and CType='dce_ref') AND (`sys_language_uid` IN (0, -1)) AND ((`tt_content`.`deleted` ```` why they want uid=0? –  Apr 17 '20 at 12:32
0

UPDATE for Typo3 v10

Typoscript:

lib.randomDCE = CONTENT
lib.randomDCE {
    table = tt_content
    select {
        pidInList = 1  // root page id
        recursive = 10
        where = {#colPos}=0 AND {#CType}='my_custom_element'
        max = 1
        languageField = sys_language_uid
        //orderBy = rand()    - does not work :-(
    }
}

Using in fluid template:

<f:cObject typoscriptObjectPath="lib.randomDCE" />
June
  • 41
  • 3