Search code examples
databasetyposcripttypo3-8.x

Select urls from Typo3 Database via Typoscript query


First my goal: I want to create a list with links to internal pages. This list has to be ordered by creation date (crdate in the DB)

To achieve this, I wrote the following code:

99 = CONTENT
99.table = pages
99.select {
    pidInList = root,-1
    selectFields = url
    orderBy = crdate
}

Sadly, this returns nothing. For debugging I played with the different properties. With

99 = CONTENT
99.table = tt_content
99.select {
    pidInList = 1
    orderBy = crdate
}

I cloned my rootpage. I got all records from it. So I know that all page records should be stored in the Pages table with the url.

What am I doing wrong here?

Additional information: Typo3 8.7, no the default backend elements are not working for me, yes I have to do it in typoscript

Thanks in advance for any suggestions.


Solution

  • The field url in the pages record does not hold the url from that page in general.
    It is used only for pages of type external URL, so the internal link to this page can be forwarded to that url.

    If you want a link list of all your pages you need to create a link to these pages:

    99 = CONTENT
    99 {
       table = pages
       select {
          // your selection here
       }
    
       renderObj = TEXT
       renderObj {
          typolink {
             parameter.field = uid
          }
       }
    }
    

    This will give you a list (if wrapping the renderObj with <li>|</li>) of complete links with page title as link text.

    If you want only urls you can add:

    typolink {
       returnLast = url
    }
    

    Without wrapping it will be a long string without separation.


    EDIT:

    99 = CONTENT
    99 {
       table = pages
       select {
          pidInList = 69
          orderBy = crdate desc
       }
       wrap = <ul>|</ul>
    
       renderObj = TEXT
       renderObj {
          wrap = <li>|</li>
          typolink {
             parameter.field = uid
          }
          if.isFalse.cObject = CONTENT
          if.isFalse.cObject {
             table = pages
             select {
                // this 'uid' is from context of current pages record we have selected above
                pidInList.field = uid
                // this 'uid' is the field from the records we are selecting here
                selectFields = uid
             }
    
             renderObj = TEXT
             // this 'uid' is the selected field above 
             // a field in the pages record of the subquery to decide if there are child pages
             renderObj.field = uid
             # renderObj.wrap = |,
          }
       }
    }