Fetch custom domain model data via TypoScript

Hey all,

I’m having a bit of trouble using the TypoScript database-query to fetch content from a custom domain model table.

I have a content element CtaWithContactPerson, which should display a heading, text and one or more contact persons. For the contact persons I’m using an inline type field:

// simplified field
'contact_persons' => [
        'label' => 'Ansprechpartner',
        'config' => [
            'type' => 'inline',
            "foreign_table" => "tt_content_contact_persons",
            "foreign_field" => "tt_content",
            'foreign_sortby' => 'sorting',
        ],
    ],

I store the inline elements in a new table, tt_content_contact_persons.
Such an inline element has these columns:

// simplified columns
'columns' => [
        'bodytext' => [
            'label' => 'Text',
            'config' => [
                'type' => 'text',
            ],
        ],
        'contact_person' => [
            'label' => 'Ansprechpartner',
            'config' => [
                'type' => 'group',
                'allowed' => 'tx_website_domain_model_teammember',
                "minitems" => 1,
                "maxitems" => 1,
            ],
        ],
    ],

There, I can select one of the team members from the table tx_website_domain_model_teammember. Those are managed on root level in a backend module. That works fine.

But now I want to display that contact person / team member in my content element, so I need to fetch it beforehand using TypoScript.

cta_with_contact_person =< lib.contentElement
cta_with_contact_person {
    templateName = CtaWithContactPerson
    dataProcessing {
        10 = database-query
        10 {
            table = tt_content_contact_persons
            pidInList.field = pid
            orderBy = sorting
            where {
                data = field:uid
                intval = 1
                wrap = tt_content=|
            }
            as = contactPersons
            dataProcessing {
                10 = database-query
                10 {
                    table = tx_website_domain_model_teammember
                    orderBy = sorting
                    where {
                        data = field:contact_person
                        intval = 1
                        wrap = uid=|
                    }
                    as = person
                    dataProcessing {
                        10 = files
                        10 {
                            references.fieldName = image
                            sorting = title
                            sorting.direction = descending
                            as = image
                        }
                    }
                }
            }
        }
    }
}

The issue is that the person array is empty. Something is not configured correctly when fetching from tx_website_domain_model_teammember. I am trying to get the team member by uid, which is stored in the field contact_person.

Content element variable dump:
Screenshot_5

What did I do wrong here? Been trying to fix this for 3 hours. Cheers!

Hi J D!

It looks like you may be missing pidInList for the query on the tx_website_domain_model_teammember table. I’ve forgotten this exact thing multiple times myself.

If it isn’t set pidInList will default to the PID of the current page. Since you’re setting it for tt_content_contact_persons, I guess the records aren’t stored on the same page.

PS! To simplify your TypoScript, try using uidInList rather than the five-line where clause. Like this: uidInList.field = uid.

— Mathias

Thanks for your tips!
I adjusted my TypoScript and now it works:

table = tx_website_domain_model_teammember
orderBy = sorting
pidInList = 0
uidInList.field = contact_person
as = person
1 Like

Hooray! Great to hear!

— Mathias