Alternative rendering for single EXT:powermail checkboxes
August 1st, 2012I was pissed off because I couldn’t find a proper option in Powermail to render a single checkbox (without a legend and all that crap).
The solution I’m using right now seems to provide exactly what I was looking for. If you create a new Checkbox field and only supply a single option, a single checkbox will be rendered. If you supply multiple options, the behavior is the same as always:
{namespace vh=Tx_Powermail_ViewHelpers}
<div id="powermail_fieldwrap_{field.uid}" class="powermail_fieldwrap powermail_fieldwrap_check powermail_fieldwrap_{field.uid} {field.css}">
<f:if condition="<f:count subject='{field.settings}' /> == 1">
<f:then>
<div class="powermail_check_outer">
<f:for each="{field.settings}" as="setting" iteration="index">
<div class="powermail_check_inner powermail_check_inner_{index.cycle}">
<f:form.checkbox name="field[{field.uid}][{index.index}]" value="{setting.value}" checked="{vh:Misc.PrefillField(field: '{field}', cycle: '{index.cycle}')}" id="powermail_field_{field.marker}_{index.cycle}" class="powermail_checkbox powermail_checkbox_{field.uid} {vh:Misc.ValidationClass(field: '{field}')}" title="{setting.label}" />
<label for="powermail_field_{field.marker}_{index.cycle}">
{field.title}<f:if condition="{field.mandatory}"><span class="mandatory">*</span></f:if>
</label>
</div>
</f:for>
</div>
</f:then>
<f:else>
<fieldset>
<legend class="powermail_label powermail_check_legend">
{field.title}<f:if condition="{field.mandatory}"><span class="mandatory">*</span></f:if>
</legend>
<div class="powermail_check_outer">
<f:for each="{field.settings}" as="setting" iteration="index">
<div class="powermail_check_inner powermail_check_inner_{index.cycle}">
<f:form.checkbox name="field[{field.uid}][{index.index}]" value="{setting.value}" checked="{vh:Misc.PrefillField(field: '{field}', cycle: '{index.cycle}')}" id="powermail_field_{field.marker}_{index.cycle}" class="powermail_checkbox powermail_checkbox_{field.uid} {vh:Misc.ValidationClass(field: '{field}')}" />
<label for="powermail_field_{field.marker}_{index.cycle}">{setting.label}</label>
</div>
</f:for>
</div>
</fieldset>
</f:else>
</f:if>
</div>
I guess I wouldn’t need the ForEachViewHelper for the single record, but I just wanted to get something working quickly. So there you have it.
