John Miller
John Miller

Reputation: 717

How to deliver TYPO3 Fluid Form elements created outside template?

How can I deliver prepared fluid form elements using PHP and have them process in a fluid template?

Something like:

Controller:

public function indexAction(): void {
  $html = '<div class="wrap">
                    <f:form.textfield name="email" value=""/>
                    <f:form.textfield name="token" value="[email protected]"/>
                </div>';
  $this->view->assign('elements', ['data' => $html]);
}

Index Template:

<f:form ...">
    <div class="F">{elements.data -> f:format.raw()}</div>
</f:form>

Upvotes: 0

Views: 331

Answers (1)

Bernd Wilke πφ
Bernd Wilke πφ

Reputation: 10791

Rendering Fluid is no iterating process and so your Fluid in a variable will not be rendered as Fluid.

If you want variants you could use partials which can be controlled by a variable

<f:if condition="{var1} == 'long'">
<f:then>
    <render partial="longVersion" arguments="{_all}" />
</f:then>
<f:else>
    <render partial="shortVersion" arguments="{_all}" />
</f:else>
</f:if>

you even can use the variabel to select the partial directly:

<f:render partial="Part_{var1}" arguments="{_all}" />

Another way would be to insert the rendered Fluid in to the variable. in Typoscript this coul be like this:

10 = FLUIDTEMPLATE
10 {
    template = outer
    variables {
        part1 = FLUIDTEMPLATE
        part1 {
            template = inner
            variables {
                :
            }
        }
        :
    }
}

or dynamically:

<f:cObject typoscriptObjectPath="lib.subtemplate">
lib.subtemplate = FLUIDTEMPLATE
lib.subtemplate {
    template = inner
    variables {
        :
    }
}

Upvotes: 1

Related Questions