DJ-Extensions tutorials: How to use custom fields in Joomla 4?
Login

New to DJ-Extensions?
23 November, 2023
Follow Us

How to use custom fields in Joomla 4?

23 November, 2023

Custom fields in Joomla 4 are a powerful feature that allows users to tailor and extend their content with specific data fields. Unlike traditional content management systems, Joomla's custom fields provide a flexible and intuitive way to gather and display information beyond the standard article parameters.

There are 17 types of custom fields which can be added:

  • calendar

  • checkboxes

  • colour

  • DJ-MediaTools album

  • editor

  • integer

  • list

  • list of images

  • media

  • radio

  • SQL

  • subform

  • text

  • text area

  • URL

  • user

  • user groups

Each field can be highly customized and used in:

  • articles

  • users profiles

  • contact forms

Of course, many of the developers probably will also start to integrate custom fields in 3rd party components.

Our components integrate with custom fields:

How to create a custom field in Joomla? Let's do an example!

Under Content menu in the backend, you can find two positions: Fields and Field Groups.

joomla 4 custom fields view

First, you need to create a group for your custom fields, click a +New button.

joomla 4 create new field groups
joomla 4 create new field groups

Then in Content - Fields, you can create fields

General field settings

joomla 4 custom fields general filed settings
  • Title: Set a field title.

  • Type: Choose one of 17 available field types.

  • Name and Label: You can add them otherwise they will be automatically generated (from the title).

  • Description: Enter a custom field description.

  • Required: You can choose that field should be required or not.

  • Default Value: You can set a default value e.g. 'sample text' words for input.

  • Filter: You can control field content with a filter. For example, you can force to use only numbers (integer) in a given field. Some of the available options: raw, safe HTML, text, alphanumeric, integer, float, telephone.

  • Maximum Length: Define a maximum length of the input.

Options for custom field

joomla 4 custom fields options for custom field

Form Options

  • Placeholder: Set input placeholder. The attribute specifies a hint that describes the expected value of the field. For example a sample value or a short description of the expected format in this field. This hint is visible in the input before the user enters a value.

  • Field Class: You can set CSS classes which will be added to the fields in output or edit form.

  • Label Class (Form): Assign a class to the label.

  • Editable In: Choose: Site / Administrator / Both

  • Showon Attribute: Conditionally show or hide the field depending on the value of other fields.

Display Options

  • Display Class: The class of the field container in the output.

  • Value Class: The class of the field value in the output.

  • Label: Choose Show / Hide

  • Label Class (Output): Add label class value

  • Automatic Display: After Title / Before Display Content / After Display Content / Do not automatically display

  • Prefix

  • Suffix

  • Layout

  • Display When Read-Only: Inherit / Yes / No

After Title - field will be visible below the article title. Example:

joomla 4 custom fields after title field example in article

Before Display - field will be displayed before the article content:

joomla 4 custom fields before display field example in article

After Display - field will be displayed below the article content:

joomla 4 custom fields after display field example in article

No - field will not be displayed by default, but you can display it manually in the article:

joomla 4 custom fields in article add field in article
joomla 4 custom fields in article add field in article
joomla 4 custom fields in article add field in article

Publishing

joomla 4 custom fields in articles publishing options

There is a possibility to assign fields to fields groups and categories. You can set the category to all or select some categories. These options give you the ability to create multiple groups and fields and display them in the specific places.

The example of filed groups:

joomla 4 custom fields in articles field groups example view

The example of custom fields:

joomla 4 custom fields in articles fields example view

How to use Joomla custom fields in the article?

Once you have custom fields, we need to set a field data. Edit the article and find a tab with a Fields group name.

joomla 4 custom fields in articles adding fields in article

You can display each custom filed directly in the article content. Simply, click Fields button in the Editor and choose field or group in the modal popup.

joomla 4 custom fields in article addinf fields from button in the editor section

You can also use plain text to display fields or groups:

where '1' is an ID of field or group.

How to use Joomla custom fields in contacts or user profiles?

Basically, it is very similar to usage in the articles. The difference is that you should add custom fields and groups under Users:

joomla 4 custom fields in users
joomla 4 custom fields add new fields in users

or in Components - Contacts:

joomla 4 custom fields in contacts
joomla 4 custom fields add new fields in contacts

What is the purpose of custom fields on Joomla site?

You can prepare many cool things, below you will find an example of the car product.

Example field:

Brand (media)

joomla 4 custom fields in article add media type field

Condition (radio)

joomla 4 custom fields in articles select radio type filed

First registration (calendar)

joomla 4 custom fields in articles select calendar type field

Interior features (checkboxes)

joomla 4 custom fields in articles checkboxes type of fields example

Article settings:

joomla 4 custom fields in articles - article field settings

Result:

joomla 4 custom fields in articles - article field website view

Unlimited possibilities of Joomla custom fields?

Almost. Custom fields are really powerful but the most important thing is you can use them in your own way!
Overrides is the key. You can use custom fields in overridden files.

Good luck!

© 2023 DJ-Extensions.com. All rights reserved.