Custom Fields

Apart from Joomla's built-in custom fields being supported within TEXTman, you can also create your own custom fields. Joomla's built-in custom fields work straight out of the box, but offers little in the way of customisation. With TEXTman's custom fields you have complete control over the form and presentation of the fields, but does require a little technical knowledge to make them work.

In this tutorial, we'll guide you on how to create your own custom fields using a template override.

  1. Add a price field in the TEXTman article form.
  2. Display the price field's value on the article in the frontend.

Custom Price Field in Article

The Framework Template System guide is a nice primer on templates and template overrides in general.

Create template overrides

To add pricing information in the article you need to create some template overrides. We are assuming that you are using the default admin template, which is Isis.

Create a new administrative template override:

/administrator/templates/isis/html/com_textman/article/form_content.html.php

And copy its contents from:

/components/com_textman/views/article/tmpl/form_content.html.php

Edit form layouts

Open the layout files for the administrator and the frontend:

  • /administrator/templates/isis/html/com_textman/article/form_content.html.php
  • /templates/protostar/html/com_textman/article/form_content.html.php

Place the following code in one of the available tabs:

<? //price ?>
<? if ($article->isParameterizable()): ?>
    <div id="foo" class="k-tab">
        <div class="k-form-group">
            <label for="param_price"><?= translate('Price') ?></label>
            <input class="k-form-control" type="text" required name="parameters[price]" id="param_price" value="<?= $article->getParameters()->price ?>" />
        </div>
    </div>
<? endif ?>

Or create a new tab exclusively for your custom field(s):

Add a new tab header

<div class="k-tabs-wrapper">
    <ul class="k-tabs">
        // ...
        <li>
            <a href="#foo" data-k-toggle="tab"><?= translate('Foo') ?></a>
        </li>
    </ul>
</div>

Then add the custom field(s) as the content of the tab

<div class="k-tabs-content">
    // ...
    <? if ($article->isParameterizable()): ?>
        <div id="foo" class="k-tab">
            <div class="k-form-group">
                <label for="param_price"><?= translate('Price') ?></label>
                <input class="k-form-control" type="text" required name="parameters[price]" id="param_price" value="<?= $article->getParameters()->price ?>" />
            </div>
        </div>
    <? endif ?>
</div>

Show price information

Create this directory in your template's html directory: /templates/[template_name]/html/com_content/article/

Copy the following file into this new directory:

/components/com_content/views/article/tmpl/default.php

Place the following markup where you would like to show the price:

<? if ($params->get('price')): ?>
<dl class="commerce-container">
    <dd class="field-entry">
        <span class="field-label ">Price: </span>
        <span class="field-value"><?= $params->get('price') ?></span>
    </dd>
</dl><br>
<? endif ?>