Search code examples
formshttp-redirectfluidextbasetypo3-9.x

Controller action - redirect to another template


I am looking for a way to redirect to another template if certain conditions are fulfilled.

Like:

public funtion redirectAction() {
 if(certain conditions = TRUE){
  REDIRECT TO ANOTHER TEMPLATE WITH DIFFERENT CONTENT
 }
}

I've seen some expressions in existing actions:

$this->redirect('list');

In this case, 'list' is the default List.html template, right? So I thought if I replaced the 'list' with a different template name, that would solve the problem. But i get a opps error.

Or is there any other solution of calling a different template?

Thank you very much!


Solution

  • with a redirect in the controller you always redirect to another function, not a template.

    For example with

    $this->redirect('list2');
    

    You would then redirect to the function list2Action() and this would expect a Template List2.html

    Often however, it is easier to use a switch in fluid. for example:

    <f:if condition="{abc} == 1">
    <f:then>
       <f:render partial="TempalteAbcTrue" arguments="{_all}" />
    </f:then>
    <f:else>
        <f:render partial="TempalteAbcFalse" arguments="{_all}" />
    </f:else>
    

    If you used the normal folder structure of extbase you have a "Layouts", "Templates" and "Partials" folder. With the example above you can create 2 files in the folder "Partials": "TempalteAbcTrue.html" and "TempalteAbcFalse.html".