TYPO3 tx_news归档页OverwriteDemand页面标题设置技术咨询
Got it, let's get your archive page sorted where you want to use the page title to set tx_news's OverwriteDemand. Here's a step-by-step solution that works with your existing List.html template and integrates the page title properly:
1. Update Your List.html Template
Your current template handles category-based titles, so we'll extend that to include the page title in both the heading/title tag and the OverwriteDemand setting. Here's the adjusted code:
<!-- List Title & OverwriteDemand Setup --> <f:if condition="{news.0.categories}"> <f:then> <f:for each="{news.0.categories}" as="category"> <n:titleTag> <f:format.htmlentitiesDecode>{f:translate(key:'archive')} - {category.title}</f:format.htmlentitiesDecode> </n:titleTag> <div class="list-title"> <h1>{f:translate(key:'archive')} - {category.title}</h1> </div> </f:for> </f:then> <f:else> <!-- Fallback to page title when no categories are present --> <n:titleTag> <f:format.htmlentitiesDecode>{f:translate(key:'archive')} - {page.title}</f:format.htmlentitiesDecode> </n:titleTag> <div class="list-title"> <h1>{f:translate(key:'archive')} - {page.title}</h1> </div> </f:else> </f:if> <!-- Set OverwriteDemand to use the page title --> <f:if condition="{page.title}"> <f:alias map="{overwriteDemand: '{newsDemand}'}"> <f:setter property="overwriteDemand.searchWords" value="{page.title}" /> </f:alias> </f:if>
This does two key things:
- Maintains your existing category-based title logic, with a clean fallback to the page title when no categories are active.
- Dynamically sets the
searchWordsproperty of the news demand to the current page's title, which fulfills your requirement to use the page title inOverwriteDemand.
2. Alternative: TypoScript Setup
If you'd rather handle this via TypoScript (which can be cleaner for global settings across multiple archive pages), add this to your site's setup TS:
plugin.tx_news.settings.list.overwriteDemand { searchWords = TEXT searchWords.data = page:title }
This will automatically inject the page title into the news demand's search parameter for all archive pages using this plugin configuration.
Key Notes:
- If you're using the Category Menu to filter news, ensure the menu's
OverwriteDemanddoesn't overwrite the page title setting. The template approach handles this naturally since it applies when the list renders, after any menu filters are applied. - The
{page.title}variable is available in Fluid templates by default, but if you're working in a partial, make sure you're passing thepageobject into the partial context if needed.
内容的提问来源于stack exchange,提问作者Jonathan Gaardlykke

