Question

I would like to show content from a fixed page if there’s no content on current page.

An example: On the mainpage (pid=58) In the right col (colPos=31) I have a news plugin with the latest item. On subpages, it’s possible to insert content in the right col (colPos=31). It could be images,text etc. BUT, if the right col is empty I would like to show the news plugin from the mainpage as a fallback option.

This is my TypoScript, but it doesn’t work. Default content from mainpage are not showed, if there's no content from current page.

lib.rightCol-1 = COA
lib.rightCol-1 {
    10 = COA
    10 {
        ## Get content from current page. 
        10 = COA
        10 < styles.content.get 
        ## Get content from colPos 31
        10.select.where = colPos=31 
        if.isTrue.current = 1 

        20 = CONTENT
        20 {
            ## IF no content on current page show content from mainpage
            stdWrap.if.isTrue.current = 1
            stdWrap.if.negate = 1
            table = tt_content
            select {
                ## Get content from mainpage
                pidInList = 58
                where = colPos=31
                orderBy = sorting
                languageField = sys_language_uid
            }
        }
    }
}
Was it helpful?

Solution 2

Thanks for answer but I couldn't get it to work. Instead this worked:

lib.rightCol-1 = CONTENT
lib.rightCol-1 < styles.content.get
lib.rightCol-1.select.where = colPos=31
lib.rightCol-1 {
    stdWrap.ifEmpty.cObject = CONTENT
    stdWrap.ifEmpty.cObject {
    table = tt_content
    select {
        pidInList = 58
        orderBy = sorting
        where = colPos = 31
        languageField = sys_language_uid
        }
    }
}

OTHER TIPS

This can be done using stdWrap.override. If stdWrap.override returns something non-empty, this value replaces the normal value stdWrap would return. In your case, this could look like this:

# Fetch the default content from the mainpage with id 58
lib.rightCol-1 = CONTENT
lib.rightCol-1 {
    table = tt_content
    select {
        pidInList = 58
        where = colPos=31
        orderBy = sorting
        languageField = sys_language_uid
    }

    # override the content from page 58 with content from the current page,
    # but only if there is content on this page
    stdWrap.override.cObject = CONTENT
    stdWrap.override.cObject {
        table = tt_content
        select {
            pidInList = this
            where = colPos=31
            orderBy = sorting
            languageField = sys_language_uid
        }
    }
}

You can also create the following behaviour:

  1. If there is content on the current page, show it.
  2. Else, walk up the rootline and take the content from the first page that has content in the column.
  3. If there is no such page, take the content from the "mainpage".

This can be done by simply setting slide = -1 to the second CONTENT-Object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top