0
votes

The official TYPO3 Documentation explains how to create (or copy) and use a lib.dynamicContent to render columns into a Fluidtemplate. I do not understand exactly whats going on in this example. The TypoScript there is:

lib.dynamicContent = COA
lib.dynamicContent {
   10 = LOAD_REGISTER
   10.colPos.cObject = TEXT
   10.colPos.cObject {
      field = colPos
      ifEmpty.cObject = TEXT
      ifEmpty.cObject {
         value.current = 1
         ifEmpty = 0
      }
   }
   20 = CONTENT
   20 {
      table = tt_content
      select {
         orderBy = sorting
         where = colPos={register:colPos}
         where.insertData = 1
      }
   }
   90 = RESTORE_REGISTER
}

I use this snippet in a ton of TYPO3 projects and often had asked myself whats going on there.

I have changed this by experimenting a bit and ended with:

lib {
  dynamicContent = COA
  dynamicContent {
    10 = CONTENT
    10 {
      table = tt_content
      select {
        orderBy = sorting
        where {
          data = field:colPos
          wrap = colPos=|
        }
      }
    }
  }
}

That seems to do "exactly the same" thing - it outputs my content when called via cObject ViewHelper.

Can somebody explain if or why this is the worse way to render Content?

Here's the link to the lib.dynamicContent-doc: https://docs.typo3.org/c/typo3/cms-fluid-styled-content/master/en-us/Installation/InsertingContentPageTemplate/Index.html#based-on-the-fluidtemplate-content-object-cobj

2

2 Answers

0
votes

Here you go!

you can try this,

# Clear out any constants in this reserved room!
styles.content >

# get content
styles.content.get = CONTENT
styles.content.get {
    table = tt_content
    select.orderBy = sorting
    select.where = colPos=0
}

# Left Column
styles.content.getLeft < styles.content.get
styles.content.getLeft.select.where = colPos=1

# Right content
styles.content.getRight < styles.content.get
styles.content.getRight.select.where = colPos=2

Also, you can use variable in the fluid page object, check this out:

    lib.pageTemplate = FLUIDTEMPLATE
    lib.pageTemplate {
        variables {        
            content = CONTENT
            content {
                table = tt_content
                select.orderBy = sorting
                select.where = colPos=0
            }

            contentRight = CONTENT
            contentRight {
                table = tt_content
                slide = -1
                select.orderBy = sorting
                select.where = colPos=2
            }        

        }
    }

You can find out more here:

Hope this make sense, Cheer...!

0
votes

You should look at this snippet together with some information about the Fluid view helper <f:cObject> which can be found here: https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/fluid/latest/CObject.html

As you can see there are the parameters data, currentValueKey and table that will be handed over to the typoscriptObjectPath, which is why the snippet makes perfect sense. The reason is, that it's a bit hard to put the different options into the where clause of the CONTENT object. So it increases readability and those registers can be easily extended.

So the register in this example is used to put in either the value of the data field colPos or if that is empty it will take the current value from the currentValueKey and if that is empty too it will fall back to a value of 0 to make sure the query won't produce an exception.

lib.dynamicContent = COA
lib.dynamicContent {
   10 = LOAD_REGISTER
   10.colPos.cObject = TEXT
   10.colPos.cObject {
      field = colPos
      ifEmpty.cObject = TEXT
      ifEmpty.cObject {
         value.current = 1
         ifEmpty = 0
      }
   }
   20 = CONTENT
   20 {
      table = tt_content
      select {
         orderBy = sorting
         where = colPos={register:colPos}
         where.insertData = 1
      }
   }
   90 = RESTORE_REGISTER
}

We used a modified version of that snippet to sneak in some more parameter values for the CONTENT object.

So we can hand over a data field pageUid, if that is not set we will use the uid of the current page. This will be overriden if the current or the target page is configured to show content from another page and finally we can trigger a slide with another data field.

lib.dynamicContent = COA
lib.dynamicContent {
    5 = LOAD_REGISTER
    5 {
        colPos.cObject = TEXT
        colPos.cObject {
            field = colPos
            ifEmpty.cObject = TEXT
            ifEmpty.cObject {
                value.current = 1
                ifEmpty = 0
            }
        }
        pageUid.cObject = TEXT
        pageUid.cObject {
            field = pageUid
            ifEmpty.data = TSFE:id
        }
        contentFromPid.cObject = TEXT
        contentFromPid.cObject {
            data = DB:pages:{register:pageUid}:content_from_pid
            data.insertData = 1
        }
    }
    20 = CONTENT
    20 {
        table = tt_content
        slide = -1
        slide.if.isTrue.field = slide
        select {
            includeRecordsWithoutDefaultTranslation = 1
            orderBy = sorting
            where = {#colPos}={register:colPos}
            where.insertData = 1
            pidInList.data = register:pageUid
            pidInList.override.data = register:contentFromPid
        }
    }
    90 = RESTORE_REGISTER
}

This enables us to make use of the <f:cObject> view helper while triggering additional parameters just by handing over some more values within the data array.