christian2222
christian2222

Reputation: 95

Cannot call controller action from top-level Fluid template

I have a self written TYPO3 extension (I used ext:extension_builder to create it)

My top-level TypoScript looks like this:

page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
    format = html
    file = EXT:cmsp/Resources/Private/Templates/User/Default.html
    partialRootPaths {
        10 = EXT:cmsp/Resources/Private/Partials/
    }
    layoutRootPaths {
        10 = EXT:cmsp/Resources/Private/Layouts/
    }
    templateRootPaths
        10 = EXT:cmsp/Resources/Private/Templates/
    }
    variables {
        content_main < styles.content.get
        content_main.select.where = colPos = 0
    }
}

I used a simple Fluid Styled Content template:

<f:link.action controller="user" action="search" class="btn btn-secondary">action link</f:link.action>

The search action is registered in ext_localconf.php:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'SimpleParser.Cmsp',
    'Cmspfe',
     [
         'User' => 'list,search'
     ],
     // non-cacheable actions
     [
         'User' => 'list,search'
     ]
);

I have also a template Search.html:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Search" />

<f:section name="content">
    <h1>Search Template</h1>

    <f:flashMessages />

    <table  class="tx_cmsp" >
        <tr>
            <th> </th>
            <th> </th>
        </tr>
    </table>
     <form action="SearchConfim.php">
        Searchterm: <input type="text" name="sTerm"><br>
<input type="submit" value="Submit">
</form> 
</f:section>
</html>

The problem is that I cannot create or follow a link in the website frontend from top-level Default.html (FLUIDTEMPLATE object) to Search.html (Extbase controller template):

<f:link.action controller="user" action="search" class="btn btn-secondary">action link</f:link.action>

I just stay on Default.html all the time, even when I click an action link of my controller. I can create external links with

<f:link.external ... ></f:link.external>

The external link is working but I cannot use a link to access Search.html. Perhaps the problem is that I use a TypoScript which does not activate the controller (in a right way). But I'm happy if anyone can help me.

Upvotes: 1

Views: 1068

Answers (2)

Oliver Hader
Oliver Hader

Reputation: 4200

It seems that Default.html is the name of the top-level rendering template in FLUIDTEMPLATE. So, I assume that <f:link.action ... tag is placed in that file - at least the currently generated link seems to confirm it and looks like the following:

index.php?id=1
&tx__%5Baction%5D=search
&tx__%5Bcontroller%5D=User
&cHash=dffabf13e973c371d14fb2e34b23d1a0

It uses tx__ as prefix which actually should be something like tx_cmsp_cmspfe (the combination of your extension name and the corresponding plugin name to be used).

Brief explanation

  • Default.html template is outside of the Extbase scope and thus does not know about the current extension, controller and plugin that shall be used
  • usually links appear in templates of the same extension (e.g. in Resources/Private/Templates/List.html)
  • otherwise according scope has to be defined explicitly (like shown below)

Solution for placing link to Extbase plugin in top-level rendering template

This example can be used outside the Extbase scope on Default.html template for the current page layout - however, it explicitly has to use the correct Extbase plugin scope:

<f:link.action
    action="search"
    controller="User"
    pluginName="Cmspfe"
    extensionName="Cmsp"
    pageUid="4321"
    class="btn btn-secondary">

    action link
</f:link.action>

Upvotes: 1

Jonas Osburg
Jonas Osburg

Reputation: 1783

Your controller name is User with an uppercase U. Use the same name in your f:link.action, if the controller is not being changed you can even remove this parameter.

Upvotes: 0

Related Questions