Print

Advanced F2C templating with Smarty

Article templating can be more than just a question of copy/pasting information from the submission form into the Joomla article. Using the Smarty template engine and some nice F2C template parameters there is a lot more possible.

compat icon 1 5compat icon 1 6compat icon 1 7 Note: This article is for those who understand the fundamentals of Form2Content and would like to create more dynamic templates or html using Smarty templating.

Conditional statements using single select lists (drop down)

compat f2c litecompat f2c proThe single select list field type is available both in F2C Lite and Pro. The following example shows how you can create different conditional statements based on the choice made by the submitter.

Single select list settings

When the single select list is used there are two columns in the field type settings. One is the 'option value', the other is the 'option display text' (see image). The choice made can be rendered in two ways into the article.

Option value (latin characters, no spacing): {$FIELDNAME}
Option display text: {$FIELDNAME_TEXT}

Example: Gender choice determining article content

In this example we will assume there is a single select list field type with unique field name GENDER. The values are 1: Male, 2: Female (as in the above image).

In our article we want our text to refer to 'him' or 'her' and 'his' or 'hers'.

Article text to create: "This box is his/hers, it therefore doesn't belong to him/her." The example will show the use of both the value and text option.

This box
{if $GENDER eq '1'}
is his
{elseif $GENDER eq '2'}
is hers
{else}
is someones
{/if}
, it therefore doesn't belong to
{if $GENDER_TEXT == 'Male'}
 her.
 {elseif $GENDER_TEXT == 'Female'}
 him.
 {else}
you.
 {/if}

The above code can render 3 options:

  1. This box is his, it therefore doesn't belong to her. (Male selected)
  2. This box is hers, it therefore doesn't belong to him. (Female selected)
  3. This box is someones, it therefore doesn't belong to you. (Nothing selected)

Of course there are many variants on display or hiding the entire option if nothing is selected. Extended Smarty documentation about conditions and possible syntax can be found here:http://www.smarty.net/manual/en/language.function.if.php

Conditional statements using multi-select lists (check boxes)

compat f2c proThe multi-select list field type is available both in F2C Pro. The following example shows how you can create different conditional statements based on the choice made by the submitter.

Form2Content no longer provides documentation for patTemplate use. All examples use Smarty templating! Old patTemplate templates are backwards compatible in Joomla 1.5 but new features have not been added.