Search code examples
phpseotypo3typo3-7.6.xtypo3-extensions

Render Link within Typoscript Controller


I'm afraid this may be a plugin specific/related question, but maybe there are some more experienced TypoScript / Extensions programmers out there, who can give me a quick hint where to look at.

I'm using the gallery plugin YAG Gallery. For SEO purposes i`d like to have the additonal links in the header for the previous and next page of an itemList.

At the moment i achieved the following: In Classes/Controller/ItemListController.php i added the following lines to the function "listAction":

$pager = $this->extListContext->getPagerCollection();
$nextLinkUid = $pager->getNextPage();
$prevLinkUid = $pager->getPreviousPage();
$prev = '<link rel="prev" href="' . $prevLinkUid . '">';
$next = '<link rel="next" href="' . $nextLinkUid . '">';
$this->response->addAdditionalHeaderData($prev . PHP_EOL . $next);

With this i get two additional tags in the <head> section of my page with

<link rel="prev" href="1">
<link rel="next" href="2">

So far, so good - i have a the right entries and i have the page uids of the prev and the next link.

Does anyone have an idea how can i get the actual link in this place? like the one which is rendered within Resources/Private/Partials/Pager/Default.html

<f:if condition="{pager.showPreviousLink}">
   <li class="previous">
      <extlist:link.action controller="{controller}" action="{action}" arguments="{extlist:namespace.GPArray(object:'{pagerCollection}' arguments:'page:{pager.previousPage}')}"><span>&lt;</span></extlist:link.action>
   </li>
</f:if>

What Action do i have to call from the controller to get a Link?

I assume I may have to use render from Classes/ViewHelpers/Link/ItemViewHelper.php in some way - but how? I can`t figure out how to transform the syntax from the Partial to some syntax i can call from within a controller.


Solution

  • For anyone wondering how i solved this:

    Instead of using addAdditionalHeaderData i added header data via a fluid viewhelper directly within the partial:

    https://github.com/YAG-Gallery/yag/pull/116