[TYPO3-english] Layouts for partials or any other way to avoid copy-paste in templates
Viktor Livakivskyi
invisible.kinder at gmail.com
Thu Aug 13 15:04:39 CEST 2015
Hi, List.
I'm working with a registration form template, which has a lot of fields. Each field has same layout, but contents may be different: textfield, set of checkboxes, dropdown with static_info_tables info, etc.
The layout of each field is such:
<div class="form__field-container">
<label class="form__field-label" for="field-{fieldname}">
<f:translate key="{fieldname}" />
<f:render partial="Required" section="Main" arguments="{field: '{fieldname}'}" />
</label>
<div class="form__field-data">
<f:render partial="FieldError" section="Main" arguments="{for: 'user.{fieldname}'}" />
---A part, that is unique---
</div>
</div>
My goal is to avoid copy-paste of a structure above, but I can't find a clean solution for this.
The most obvious idea is to move this code to a partial, but then I need somehow deal with unique contents of each field, which will result either in invention of too much variables and lot of if-else in Fluid template, or in creating a partial for each field, that has some differences, or even in combination of these both. This seems kinda dirty way for me.
It would be nice to have a possibility to define a layout for a section or make it possible to render a template section from a partial. Something, like this:
Partials/Field.html:
<div class="container">
<label>label</label>
<div class="field">
<f:render section="field-data" />
</div>
</div>
And then in template call it like this:
Templates/RegistrationForm.html
..
<f:render partial="Field">
<f:section name="field-data">
---all the fancy and unique stuff here---
<f:form.textfield ... />
</f:section>
</f:render>
So, the question, how do you code your forms without field's layout copy-paste?
More information about the TYPO3-english
mailing list