Search code examples
htmltypo3typoscript

Rendering content element by Uid


I'm trying to render a content element only by having it's Uid. It's supposed to be the login form of fe_login placed directly into a navigation Overlay.

I tried saving the element into a variable by using CONTENT. It did not work, obviously. But I'm not even sure if I used used the correct syntax.

page.10.variables.contentLogin = CONTENT
page.10.variables.contentLogin {
    table = tt_content
    select.where {
        uidInList = 32
        pidInList = 0
    } 
}

And the same for lib.loginContent.

Added both respectively with

{contentLogin -> f:format.raw()}
<f:cObject typoscriptObjectPath="lib.loginContent"/>

But this only renders the object I already have on this page and not the element I am looking for globally.

EDIT: I found the solution. See my own answer.


Solution

  • I found the solution. The problem in my code is the select.where statement.

    The working code is:

    lib.loginContent = CONTENT
    lib.loginContent {
        table = tt_content
        select {
            uidInList.field = myUid
            pidInList = 0
        } 
    }
    

    and in HTML

    <f:cObject typoscriptObjectPath="lib.loginContent" data="{myUid: 32}"/>
    

    The change I made was to just delete the ".where" from the select. After checking the Doc again and again I finally realized my mistake. I hope other people will find this question and answer useful as I did not find anything on the internet that could help me with the problem.

    Code for static content element:

    lib.foo = CONTENT
    lib.foo {
        #tt_content is the default table. I just like to write down where Im looking for it
        table = tt_content
        select {
            uidInList.field = Your ContentElement ID goes here!
            pidInList = 0
        }
    }
    

    <f:cObject typoscriptObjectPath="lib.loginContent">
    

    That's it. Enjoy!