chicky
chicky

Reputation: 135

Pass Fluid variable to TypoScript

I want to pass a variable (uid of category) in Fluid to a TypoScript :

 <f:cObject typoscriptObjectPath="lib.testFluid" data="{setting.myvar}/>

Then i want to use the var to get all content elements in folder with pid 942 and the category {setting.myvar}

lib.testFluid = COA
lib.testFluid = CONTENT
lib.testFluid {
table = tt_content
    select {
    pidInList = 942
    where = selected_categories = |

}

}

This does not work, it creates an MySql syntax error. I also tried using current = 1 instead of the where clause without success. I looked at post TYPO3: pass variable to typoscript via cObject? and I can recreate it but it does not work with my script. (TYPO3 8) If i use

...
    where = selected_categories = 13
....

the scrip will succesfully display all CE with category 13. How do i make it work with a var?

Upvotes: 0

Views: 2301

Answers (2)

Stefan Padberg
Stefan Padberg

Reputation: 527

I had to solve it once with markers. I couldn't find another simpler way. I give you a very general solution which you may adapt to your needs. For example you could set the pid value via a typoscript setting which is more elegant than to put it in the snippet code. Please try:

<f:cObject typoscriptObjectPath="lib.testFluid" data="{category: setting.myvar, catPid: 942}" currrentValueKey="category" />

The related TypoScript snippet:

lib.testFluid = COA
lib.testFluid {
    10 = LOAD_REGISTER
    10 {
        category.cObject = TEXT
        category.cObject.value.current = 1
        catPid.cObject = TEXT
        catPid.cObject.value.dataWrap = { field: catPid }
    }
    20 = CONTENT
    20 {
        table = tt_content
        select {
            pidInList.cObject = TEXT
            pidInList.cObject.dataWrap = {REGISTER:catPid}
            where = selected_categories=###category###
            markers {
                category.data = REGISTER:category
            }
        }
    }
    30 = RESTORE_REGISTER
}

Upvotes: 0

webman
webman

Reputation: 1203

could you try this:

<f:cObject typoscriptObjectPath="lib.testFluid" data="{myvar: setting.myvar}/>

lib.testFluid = CONTENT
lib.testFluid {
    table = tt_content
    select {
        pidInList = 942
        where.data = field:myvar
        where.intval = 1
        where.wrap = selected_categories=|
    }
}

hard to test for me but it might work ...

Upvotes: 2

Related Questions