Hi. How can we help?

Custom Fields

Last updated: 27 February 2024

DOCman is fully integrated with Joomla custom fields, letting you quickly and easily display any custom fields that you want to be associated with a document.

Adding custom fields to a document

Custom fields are added to DOCman in much the same way as they are added in the Joomla content component, when you add them to an article. If you're not familiar with Joomla content custom fields then you should first read one the following Joomla documents, dependant on your site's Joomla version:


From the sidebar menu click the Components down arrow, then the DOCman down arrow to see the Fields and Field Groups links, both links are also available via the DOCman dashboard.

Displaying custom field values in the frontend of your site

Basic

The most basic way to display the custom fields in the frontend of your website is to use the field display options in the Options tab of the field.

Scroll down to Display options then to the Automatic Display parameter, from here you can select to automatically display the custom fields after the document's title, before the document's description, or after the document's description.

If you want to display your custom field within your document's description then you can do so by using Joomla's field editor button. In this instance set the automatic display parameter's value to Do not automatically display.

Advanced

Just like the Joomla content component allows you to render custom fields in your Joomla template's /html/com_content overrides, custom fields in DOCman can be rendered in your Joomla template's /html/com_docman overrides. The process in DOCman is a little easier than it is in the Joomla content component because there's no need for you to load the fields helper first, DOCman takes care of that bit for you.

Render custom fields using the fields template helper

DOCman's fields template helper allows you to render either an entire field group or an individual field.

To render an entire field group, for example all of the custom fields that belong to the custom field group with ID = 2:


  <?= helper(‘fields.render’, [‘entity’ => $document, ‘group’ => 2]) ?>

To render individual custom fields, you have a few options.

You can render a single custom field by its ID, for example render the custom field with ID = 16:


  <?= helper(‘fields.render’, [‘entity’ => $document, ‘id’ => 16]) ?>

You can render multiple individual custom fields by their ID, for example render the custom fields with ID = 2 and 3:


  <?= helper(‘fields.render’, [‘entity’ => $document, ‘id’ => [2,3]]) ?>

Or, You can render multiple individual custom fields by their ID or Name, for example render the custom fields with ID = 2 and Name = foo and bar:


  <?= helper(‘fields.render’, [‘entity’ => $document, ‘id’ => [2,‘foo’, ‘bar’]]) ?> 

Render custom fields using the PHP API

If you want to render you custom fields within a document view template override you can also do so using the PHP API.

You can use the PHP API to render all of the custom fields that belong to a document:


<?= 
	$fields = $document->getFields(); // Fetch all fields from document
	foreach($fields as $field) {
			$output = sprintf(‘Field label: %s - Field value: %s - Field rawvalue: %s’, $field->label, $field->value, $field->rawvalue);
	}
?>

You can use the PHP API to render all of the custom fields that are assigned to a field group and belong to a document:


<?= 
	$fields = $document->getFields(13); // Fetch fields from document assigned to the custom field group with ID 13
?>

You can use the PHP API to render all of the custom fields that are not assigned to any field group and belong to a document:


<?= 
	$fields = $document->getFields(0); // Fetch fields from document not assigned to a custom field group
?>

You can use the PHP API to render individual custom fields that belong to a document:


<?= 
	$field = $document->getField(‘foo’); // Fetch a field for the current document by name
	$field = $document->getField(18); // Fetch a field for the current document by ID
?>