1
votes

I use TYPO3 v 9.5.8 together with tx_news (7.2.0).

I really like the new TYPO3 implemented speaking url generation.

I already configured it to generated speaking urls and configurated it to generate speaking urls for tx_news too, both is working fine. But I also want to show the last three news entries in page footer.

My solution was to generate them in typoscript setup and pass them to fluid template. My current typoscript code looks like this:

    news = CONTENT
    news {
        table = tx_news_domain_model_news
        select {
            pidInList = 24
            max = 3
            orderBy = datetime DESC
        }
        renderObj = COA
        renderObj {
            1 = TEXT
            1.field = datetime
            1.strftime = %d. %B %Y
            1.wrap = <p>|</p>

            2 = TEXT
            2 {
                field = title
                typolink {
                    parameter = 26
                    parameter.override.field = internalurl
                    useCacheHash = 0
                    additionalParams.wrap = &tx_news_pi1[news]=|
                    additionalParams.field = uid
                }
            }
        }
        renderObj.wrap = <div class="header-news-item">|</div>
    }

At least this works. But since I use additionalParams.wrap to append the id of the news entry, the generated url looks like this:

<a href="/allgemeines/news/artikel?tx_news_pi1[news]=2&cHash=8b0067dc86ab1392bb84cbf58878e72d">Lorem ipsum dolor sit</a>

I want to url to look like this:

<a href="/allgemeines/news/artikel/lorem-ipsum-dolor-sit">Lorem ipsum dolor sit</a>

This is the same as tx_news list view generates for redirecting to detail view.

Does somebody got an idea how this is possible?

2

2 Answers

1
votes

I guess you are missing action & controller in generating your TypoScript.

1
votes

With the hint from Georg Ringer, I got it working.

Here's the working example, beginning with TypoScript:

news = CONTENT
news {
    table = tx_news_domain_model_news
    select {
        pidInList = 24 // Page ID of the page that contains the news entries.
        max = 3
        orderBy = datetime DESC
    }
    renderObj = COA
    renderObj {
        1 = TEXT
        1.field = datetime
        1.strftime = %d. %B %Y
        1.wrap = <p>|</p>
        2 = TEXT
        2 {
            field = title
            typolink {
                parameter = 26 // Page ID of the page that displays the detail view.
                parameter.override.field = internalurl
                useCacheHash = 0
                additionalParams.wrap = &tx_news_pi1[action]=detail&tx_news_pi1[controller]=News&tx_news_pi1[news]=|
                additionalParams.field = uid
            }
        }
    }
    renderObj.wrap = <div class="header-news-item">|</div>
}

To get it working, you have to enable speaking urls for tx_news too, of course. You can do this since TYPO3 9 LTS by adding this to the site yaml config file:

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment

This is descripted here.