<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Continga</id>
	<title>Joomla! Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Continga"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Continga"/>
	<updated>2026-07-02T14:41:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=633994</id>
		<title>Custom fields type: Subfields</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=633994"/>
		<updated>2019-10-14T15:45:26Z</updated>

		<summary type="html">&lt;p&gt;Continga: Update doc after PR got merged&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This is a feature of Joomla! 4.0&lt;br /&gt;
&lt;br /&gt;
Custom fields in Joomla! is a technology to extend various item types (content articles, contact items, etc.) with custom-made fields. We could e.g. extend a content article with a text field named &#039;&#039;fact_checked_by&#039;&#039;, and every content article would then get a text field where the administrator could enter a name. For a basic introduction into this topic see [[J3.x:Adding custom fields]].&lt;br /&gt;
&lt;br /&gt;
This wiki page is an introduction into a specific type of custom fields, called &#039;&#039;subfields&#039;&#039;. The type of a custom field defines it&#039;s behavior - think of the just mentioned &#039;&#039;fact_checked_by&#039;&#039; field, which is of type &#039;text&#039; - you directly know what that means, it is a textfield where you can enter text, and that text is then being displayed.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfields&#039;&#039; type is a bit more complex; the aim of it is to provide the user the possibility to create a repeatable custom field for an item with multiple related fields. That sounds more complex than it is. It basically means: A &#039;&#039;subfields&#039;&#039; field is a custom field which can contain an arbitrary amount of other fields, forming a repeatable list. For instance: Adding a &#039;&#039;subfields&#039;&#039; custom field with the name &#039;&#039;ingredients&#039;&#039; and the sub fields &#039;&#039;description&#039;&#039; (text) and &#039;&#039;amount&#039;&#039; (integer) to a content article. What do we have then? We have an article which can contain a list of descriptions and amounts. What is that? Correct, e.g. a list of ingredients - so we basically added information to our article that allows is to interpret it, for example, as a recipe.&lt;br /&gt;
&lt;br /&gt;
A very short note on terminology, just for people who take it very accurate: As you might have noticed, we use the term &amp;quot;sub fields&amp;quot; to describe two different things: First, &#039;&#039;subfields&#039;&#039; is the &#039;&#039;&#039;type&#039;&#039;&#039; of a custom field that is being added to an item, so the type of the top-level &amp;quot;parent field&amp;quot; - so like other custom fields can be of type &#039;&#039;text&#039;&#039; or &#039;&#039;integer&#039;&#039;, we use the term &#039;&#039;subfields&#039;&#039; to describe the type of a custom field. But, secondly, we also call the configured &amp;quot;child fields&amp;quot; of this parent field &amp;quot;sub fields&amp;quot;, just because that is comfortable: We have a parent field which contains child fields, so calling those child fields sub fields is handy. This maybe can get confusing, but we think it should always be clear what is being meant due to context. If that shouldn&#039;t be the case anywhere, we try to use different terms (like above, when we spoke of parent and child fields). Additionally, we will always write the type as &#039;&#039;subfields&#039;&#039; whilest when talking about the child fields, we will just call them sub fields. This is just a note for very attentive readers, and most of the people who are reading this should not care about this.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom field to be used as a sub field ==&lt;br /&gt;
&lt;br /&gt;
Before creating a new &#039;&#039;subfields&#039;&#039; instance you must create one or more normal custom fields that serve as child fields for that &#039;&#039;subfields&#039;&#039; instance. So, for example, when you want to add a repeatable &#039;&#039;subfields&#039;&#039; instance called &#039;&#039;ingredients&#039;&#039; to an article with the sub fields &#039;&#039;description&#039;&#039; (type text) and &#039;&#039;amount&#039;&#039; (type integer), you have to first create the two custom fields &#039;&#039;description&#039;&#039; and &#039;&#039;amount&#039;&#039; as separate, own custom fields.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note about subfields-only fields&#039;&#039;&#039;: By default, a newly created custom field will have its &amp;quot;Category&amp;quot; assignment set to &amp;quot;All&amp;quot;. This means that this custom field will be used for all items of all categories of the relevant context (e.g. content articles). When you integrate such a custom field into a &#039;&#039;subfields&#039;&#039; instance, you basically will see the sub field twice when editing an item: One time as a standalone field as part of that item, and the other time included into the &#039;&#039;subfields&#039;&#039; instance as a sub field. You can circumvent this problem by declaring the sub field to be not available for an item directly: To do this, simply set the &amp;quot;Category&amp;quot; of that sub field to &amp;quot;None&amp;quot;. By doing this, this custom field will not be part of any item itself, being only part of the &#039;&#039;subfields&#039;&#039; instance.&lt;br /&gt;
&lt;br /&gt;
== The &#039;&#039;subfields&#039;&#039; field ==&lt;br /&gt;
&lt;br /&gt;
Provides a possibility to add several (repeatable) sub fields to an item. The sub fields are each rendered by themselves and the result will by default be shown as a comma-separated list (this can be changed, see further down).&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;subfields&#039;&#039; specific options ===&lt;br /&gt;
&lt;br /&gt;
* Repeatable, &#039;&#039;repeat&#039;&#039; (mandatory) boolean, default true.&amp;lt;br /&amp;gt;Whether the sub fields should be repeatable, i.e. allowing multiple lines of values.&lt;br /&gt;
* Sub fields (mandatory)&amp;lt;br /&amp;gt;A list of other custom field items that shall be used as sub fields for this item.&amp;lt;br /&amp;gt;Render values, &#039;&#039;render_values&#039;&#039; (mandatory) boolean, default true. Whether the value of this sub field shall get rendered or not (see next chapter).&lt;br /&gt;
&lt;br /&gt;
=== Disable rendering for a sub field ===&lt;br /&gt;
&lt;br /&gt;
When creating a &#039;&#039;subfields&#039;&#039; instance and selecting, which other custom fields should be used as sub fields, you are able to select whether you want Joomla! to render this sub fields&#039; value, when the value of the parent field is being rendered. &#039;&#039;&#039;Normally, this is what you want to do,&#039;&#039;&#039; why the default value is &#039;&#039;true&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Turning this off will have consequences for sub field types for which the value, which is saved in the database, is not equal to the rendered string which is normally being used in the frontend: E.g. the &#039;&#039;media&#039;&#039; type stores a path to a media file in the database, but normally renders as an &#039;&#039;&amp;lt;img&amp;gt;&#039;&#039;-tag. Turning this option off would mean that the default rendering process of the sub field will now show the path the file instead of the &#039;&#039;&amp;lt;img&amp;gt;&#039;&#039;-tag.&lt;br /&gt;
&lt;br /&gt;
So, why does this option exist? Because rendering of multiple fields, maybe multiple hundreds of fields, costs performance, and rendering of many sub fields of many items takes much performance and time. And this is not always what you want, nor what you need: You are able to switch this option off and create your own rendering procedure by creating a layout override for your sub fields (see next chapter), so this will render the sub fields exactly as you want it, and you can disable the Joomla! default rendering with it.&lt;br /&gt;
&lt;br /&gt;
== Changing the rendering with a layout override ==&lt;br /&gt;
&lt;br /&gt;
By default, the value of all individual sub fields will be rendered and the result will be shown as a comma-separated list in the frontend. This default behavior is implemented in the file &#039;&#039;plugins/fields/subfields/tmpl/subfields.php&#039;&#039;, please take a look at it to get a first impression on how to change the rendering in general.&lt;br /&gt;
&lt;br /&gt;
The first thing to do to change the rendering is to create a layout override for that template, e.g. by creating a new file &#039;&#039;templates/$YOUR_TEMPLATE/html/plg_fields_subfields/subfields.php&#039;&#039;, see [[Layout Overrides in Joomla]] for further info.&lt;br /&gt;
&lt;br /&gt;
The next thing to do is to get an idea about the structure of the &#039;&#039;$field&#039;&#039; object that is being passed to the template. That object has 2 important properties:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;name&#039;&#039; is a string containing the name of the custom field.&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;subfields_rows&#039;&#039; is an array containing arrays, which contain the sub fields. So, basically, &#039;&#039;$field-&amp;gt;subfields_rows&#039;&#039; contains rows of data, and each row contains a list of sub field instances / objects. Each of those instances is a fully-featured field instance / object itself, and has properties like &#039;&#039;name&#039;&#039;, &#039;&#039;type&#039;&#039;, etc. amongst &#039;&#039;value&#039;&#039; and &#039;&#039;rawvalue&#039;&#039;, containing the rendered and unrendered value respectively.&lt;br /&gt;
&lt;br /&gt;
You can use the &#039;&#039;name&#039;&#039; property of &#039;&#039;$field&#039;&#039; to make distinctions in your template, dependent on which &#039;&#039;subfields&#039;&#039; instance is being rendered.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfields_rows&#039;&#039; property might sound a bit complicated in the first place, but when you create your own layout override and play around with it, look at different states (e.g. by using a debugger, or &#039;&#039;var_dump()&#039;&#039;) etc., you should get a good feeling about how it behaves very quickly.&lt;br /&gt;
&lt;br /&gt;
=== Example 1 ===&lt;br /&gt;
&lt;br /&gt;
Suppose we have created a &#039;&#039;subfields&#039;&#039; instance named &#039;&#039;ingredients&#039;&#039; for an article, that contains the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;image&#039;&#039; of type &#039;&#039;text&#039;&#039; and &#039;&#039;media&#039;&#039; respectively. We now want to display those in a nice way when we are asked to render them. We could e.g. do this in the following way, note the different use of &#039;&#039;rawvalue&#039;&#039; and &#039;&#039;value&#039;&#039; here, which we use to get access to the rendered value of the &#039;&#039;media&#039;&#039; field (which is, normally, an &amp;lt;img&amp;gt; HTML tag):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php if ($field-&amp;gt;name == &#039;ingredients&#039;): ?&amp;gt;&lt;br /&gt;
  &amp;lt;ul&amp;gt;&lt;br /&gt;
    &amp;lt;?php foreach ($field-&amp;gt;subfields_rows as $row): ?&amp;gt;&lt;br /&gt;
      &amp;lt;li&amp;gt;&lt;br /&gt;
        Description: &amp;lt;?php echo htmlentities($row[&#039;description&#039;]-&amp;gt;rawvalue); ?&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
        Image: &amp;lt;?php echo $row[&#039;image&#039;]-&amp;gt;value; ?&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
  &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you could disable the rendering of the &#039;&#039;description&#039;&#039; sub field in this example (because the rendered value is not being used, only the raw value), see also previous chapter.&lt;br /&gt;
&lt;br /&gt;
=== Example 2 ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfields_rows&#039;&#039; object can get a little complicated. The following code will render all sub fields in a comma-separated list, using their &#039;&#039;rawvalue&#039;&#039; and prefixing them with their name. This example shows how the &#039;&#039;subfield_rows&#039;&#039; object can be used on a more basic-level, not using any rendered values.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &#039;&amp;lt;ul&amp;gt;&#039;;&lt;br /&gt;
foreach ($field-&amp;gt;subfields_rows as $row)&lt;br /&gt;
{&lt;br /&gt;
  echo &#039;&amp;lt;li&amp;gt;&#039;;&lt;br /&gt;
  $buffer = array();&lt;br /&gt;
  foreach ($row as $subfield)&lt;br /&gt;
  {&lt;br /&gt;
    $buffer[] = (&lt;br /&gt;
      $subfield-&amp;gt;name . &#039;: &#039;&lt;br /&gt;
      . $subfield-&amp;gt;rawvalue&lt;br /&gt;
    );&lt;br /&gt;
  }&lt;br /&gt;
  echo implode(&#039;, &#039;, $buffer);&lt;br /&gt;
  echo &#039;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
}&lt;br /&gt;
echo &#039;&amp;lt;/ul&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Custom Fields]]&lt;br /&gt;
[[Category:Beginners]]&lt;br /&gt;
[[Category:Joomla! Website Management]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Continga</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=588485</id>
		<title>Custom fields type: Subfields</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=588485"/>
		<updated>2019-01-24T16:43:55Z</updated>

		<summary type="html">&lt;p&gt;Continga: updated to latest status of PR&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Note ==&lt;br /&gt;
&lt;br /&gt;
The feature described on this page is not yet part of the Joomla! core. It is currently being handled as a pull request on GitHub, see https://github.com/joomla/joomla-cms/pull/22446 . This wiki page reflects the current status of that PR. This preliminary note should get removed when the PR got merged.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Custom fields in Joomla! is a technology to extend various item types (content articles, contact items, etc.) with custom-made fields, e.g. extending a content article with a text field named &#039;&#039;fact_checked_by&#039;&#039;. For a basic introduction into this topic see [[J3.x:Adding custom fields]]. &lt;br /&gt;
&lt;br /&gt;
This wiki page is an introduction into a special type for custom fields called &#039;&#039;subfields&#039;&#039;. The aim of the &#039;&#039;subfields&#039;&#039; custom field type is to provide the user the possibility to create a repeatable custom field for an item with multiple related fields, so e.g. adding a custom field named &#039;&#039;ingredients&#039;&#039; with the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;amount&#039;&#039; to a content article.&lt;br /&gt;
&lt;br /&gt;
A short note on terminology: We use the term &amp;quot;sub fields&amp;quot; to describe two different things: First, &#039;&#039;subfields&#039;&#039; is the &#039;&#039;&#039;type&#039;&#039;&#039; of the custom field that is being added to an item, so the type of the &amp;quot;parent field&amp;quot; - e.g. like other custom fields can be of type &#039;&#039;text&#039;&#039; or &#039;&#039;integer&#039;&#039;. Second, we call the configured &amp;quot;child fields&amp;quot; of that parent field &amp;quot;sub fields&amp;quot;, just because that is comfortable. An attentive reader will note the difference, but the context should always be clear what is meant. If that is not the case, we use other terms.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom field to be used as a sub field ==&lt;br /&gt;
&lt;br /&gt;
Before creating a new subfields instance you will want to create one or more custom fields that serve as child fields for the subfields instance you are about to create. So e.g. when you want to add a repeatable subfields instance to an article called &#039;&#039;ingredients&#039;&#039; with the sub fields &#039;&#039;description&#039;&#039; (type text) and &#039;&#039;amount&#039;&#039; (type integer), you have to first create the two custom fields &#039;&#039;description&#039;&#039; and &#039;&#039;amount&#039;&#039; as separate custom fields. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note about subfields-only fields&#039;&#039;&#039;: By default, a newly created custom field will have its &amp;quot;Category&amp;quot; filter set to &amp;quot;All&amp;quot;. This means, that custom field will be displayed for items of all categories. If you integrate this custom field into a subfields instance, this basically means you will see the sub field twice: One time as a standalone field as part of that item, and the other time included into the subfields instance as a sub field. You can circumvent this problem by declaring the sub field to be not available for an item directly. To do this, simply set the &amp;quot;Category&amp;quot; of that sub field to &amp;quot;None&amp;quot;. By doing this, this custom field will not be part of any item itself.&lt;br /&gt;
&lt;br /&gt;
== The subfields field ==&lt;br /&gt;
&lt;br /&gt;
Provides a possibility to add several (repeatable) sub fields to an item. The sub fields are each rendered by themselves and the result will by default be shown as a comma-separated list (this can be changed, see further down).&lt;br /&gt;
&lt;br /&gt;
=== Options ===&lt;br /&gt;
&lt;br /&gt;
* Repeatable, &#039;&#039;repeat&#039;&#039; (mandatory) boolean, default true.&amp;lt;br /&amp;gt;Whether the sub fields should be repeatable in the backend.&lt;br /&gt;
* Sub fields (mandatory)&amp;lt;br /&amp;gt;A list of other custom field items that shall be used as sub fields for this item.&amp;lt;br /&amp;gt;Render values, &#039;&#039;render_values&#039;&#039; (mandatory) boolean, default true. Whether the value of this sub field shall get rendered or not (see next chapter).&lt;br /&gt;
&lt;br /&gt;
=== Disable rendering for a sub field ===&lt;br /&gt;
&lt;br /&gt;
When creating a subfields instance and selecting which other custom fields should be used as sub fields, you are able to select whether you want Joomla! to render this sub fields&#039; value, when the value of the parent field is being rendered. &#039;&#039;&#039;Normally, this is what you want to do,&#039;&#039;&#039; why the default value is &#039;&#039;true&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Turning this off will have consequences for sub field types for which the value, which is saved in the database, is not equal to the rendered string which is normally being used in a template: E.g. the &#039;&#039;media&#039;&#039; type which stores a path to a media file in the database, but normally renders as an &#039;&#039;&amp;lt;img&amp;gt;&#039;&#039;-tag. Turning this option off would mean that the default rendering process of the subfields field will now show the path the file instead of the &#039;&#039;&amp;lt;img&amp;gt;&#039;&#039;-tag.&lt;br /&gt;
&lt;br /&gt;
So, why does this option then even exist? Because rendering takes performance, and rendering of many sub fields of many items takes much performance and time. And this is not always what you want, nor what you need. You are basically able to switch this option off and create your own layout override for your subfields (see next chapter) - hence rendering the sub fields the way you want and saving performance by it.&lt;br /&gt;
&lt;br /&gt;
== Changing the rendering with a layout override ==&lt;br /&gt;
&lt;br /&gt;
By default, the value of all individual sub fields will be rendered and the result will be shown as a comma-separated list in the frontend. This default behavior is implemented in the file &#039;&#039;plugins/fields/subfields/tmpl/subfields.php&#039;&#039;, please take a look at it to get a first impression on how to change the rendering in general.&lt;br /&gt;
&lt;br /&gt;
The first thing to do to change the rendering is to create a layout override for that template, e.g. by creating a new file &#039;&#039;templates/$YOUR_TEMPLATE/html/plg_fields_subfields/subfields.php&#039;&#039;, see [[Layout Overrides in Joomla]] for further info.&lt;br /&gt;
&lt;br /&gt;
The next thing to do is to get an idea about the structure of the &#039;&#039;$field&#039;&#039; object that is being passed to the template. That object has 2 important properties:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;name&#039;&#039; is a string containing the name of the custom field you set.&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;subfields_rows&#039;&#039; is an array containing arrays, which contain the sub fields. So, basically, &#039;&#039;$field-&amp;gt;subfields_rows&#039;&#039; contains rows of data, and each row contains a list of sub field instances / objects. Each of those instances is a fully-featured field instance / object itself, and has properties like &#039;&#039;name&#039;&#039;, &#039;&#039;type&#039;&#039;, etc. amongst &#039;&#039;value&#039;&#039; and &#039;&#039;rawvalue&#039;&#039;, containing the rendered and unrendered value respectively.&lt;br /&gt;
&lt;br /&gt;
You can use the &#039;&#039;name&#039;&#039; property of &#039;&#039;$field&#039;&#039; to make distinctions in your template, dependent of which subfields instance is being rendered.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfields_rows&#039;&#039; property might sound a bit complicated in the first place, but when you create your own layout override and play around with it, &#039;&#039;var_dump()&#039;&#039; different states etc., you should get a good feeling about how it behaves very quickly.&lt;br /&gt;
&lt;br /&gt;
=== Example 1 ===&lt;br /&gt;
&lt;br /&gt;
Suppose we have created a custom field named &#039;&#039;ingredients&#039;&#039; for an article that contains the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;image&#039;&#039; of type &#039;&#039;text&#039;&#039; and &#039;&#039;media&#039;&#039; respectively. We now want to display those in a nice way when we are asked to render them. We could e.g. do this in the following way, note the different use of &#039;&#039;rawvalue&#039;&#039; and &#039;&#039;value&#039;&#039; here, which we use to get access to the rendered value of the &#039;&#039;media&#039;&#039; field (which is, normally, an &amp;lt;img&amp;gt; HTML tag):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php if ($field-&amp;gt;name == &#039;ingredients&#039;): ?&amp;gt;&lt;br /&gt;
  &amp;lt;ul&amp;gt;&lt;br /&gt;
    &amp;lt;?php foreach ($field-&amp;gt;subfields_rows as $row): ?&amp;gt;&lt;br /&gt;
      &amp;lt;li&amp;gt;&lt;br /&gt;
        Description: &amp;lt;?php echo htmlentities($row[&#039;description&#039;]-&amp;gt;rawvalue); ?&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
        Image: &amp;lt;?php echo $row[&#039;image&#039;]-&amp;gt;value; ?&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
  &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you could disable the rendering of the &#039;&#039;description&#039;&#039; sub field in this example (because the rendered value is not being used, only the raw value), see also previous chapter.&lt;br /&gt;
&lt;br /&gt;
=== Example 2 ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfields_rows&#039;&#039; object can get a little complicated. The following code will render all sub fields in a comma-separated list, using their &#039;&#039;rawvalue&#039;&#039; and prefixing them with their name. This example shows how the &#039;&#039;subfield_rows&#039;&#039; object can be used on a more basic-level, not using any rendered values.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &#039;&amp;lt;ul&amp;gt;&#039;;&lt;br /&gt;
foreach ($field-&amp;gt;subfields_rows as $row)&lt;br /&gt;
{&lt;br /&gt;
  echo &#039;&amp;lt;li&amp;gt;&#039;;&lt;br /&gt;
  $buffer = array();&lt;br /&gt;
  foreach ($row as $subfield)&lt;br /&gt;
  {&lt;br /&gt;
    $buffer[] = (&lt;br /&gt;
      $subfield-&amp;gt;name . &#039;: &#039;&lt;br /&gt;
      . $subfield-&amp;gt;rawvalue&lt;br /&gt;
    );&lt;br /&gt;
  }&lt;br /&gt;
  echo implode(&#039;, &#039;, $buffer);&lt;br /&gt;
  echo &#039;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
}&lt;br /&gt;
echo &#039;&amp;lt;/ul&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Custom Fields]]&lt;br /&gt;
[[Category:Beginners]]&lt;br /&gt;
[[Category:Joomla! Website Management]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Continga</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=587561</id>
		<title>Custom fields type: Subfields</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=587561"/>
		<updated>2019-01-17T18:24:12Z</updated>

		<summary type="html">&lt;p&gt;Continga: Adapt to newest status of the pull request&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Note ==&lt;br /&gt;
&lt;br /&gt;
The feature described on this page is not yet part of the Joomla! core. It is currently being handled as a pull request on GitHub, see https://github.com/joomla/joomla-cms/pull/22446 . This wiki page reflects the current status of that PR. This preliminary note should get removed when the PR got merged.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Custom fields in Joomla! is a technology to extend various item types (content articles, contact items, etc.) with custom-made fields, e.g. extending a content article with a text field named &#039;&#039;fact_checked_by&#039;&#039;. For a basic introduction into this topic see [[J3.x:Adding custom fields]]. &lt;br /&gt;
&lt;br /&gt;
This wiki page is an introduction into a special type for custom fields called &#039;&#039;subfields&#039;&#039;. The aim of the &#039;&#039;subfields&#039;&#039; custom field type is to provide the user the possibility to create a repeatable custom field for an item with multiple related fields, so e.g. adding a custom field named &#039;&#039;ingredients&#039;&#039; with the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;amount&#039;&#039; to a content article.&lt;br /&gt;
&lt;br /&gt;
A short note on terminology: We use the term &amp;quot;sub fields&amp;quot; to describe two different things: First, &#039;&#039;subfields&#039;&#039; is the &#039;&#039;&#039;type&#039;&#039;&#039; of the custom field that is being added to an item, so the type of the &amp;quot;parent field&amp;quot; - e.g. like other custom fields can be of type &#039;&#039;text&#039;&#039; or &#039;&#039;integer&#039;&#039;. Second, we call the configured &amp;quot;child fields&amp;quot; of that parent field &amp;quot;sub fields&amp;quot;, just because that is comfortable. An attentive reader will note the difference, but the context should always be clear what is meant. If that is not the case, we use other terms.&lt;br /&gt;
&lt;br /&gt;
== The subfields field ==&lt;br /&gt;
&lt;br /&gt;
Provides a possibility to add several (repeatable) sub fields to an item. The sub fields are each rendered by themselves and the result will by default be shown as a comma-separated list (this can be changed, see further down).&lt;br /&gt;
&lt;br /&gt;
=== Options ===&lt;br /&gt;
&lt;br /&gt;
* Repeatable, &#039;&#039;repeat&#039;&#039; (mandatory) boolean, default true.&amp;lt;br /&amp;gt;Whether the sub fields should be repeatable in the backend.&lt;br /&gt;
* Sub fields (mandatory)&amp;lt;br /&amp;gt;A list of other custom field items that shall be used as sub fields for this item.&amp;lt;br /&amp;gt;Render values, &#039;&#039;render_values&#039;&#039; (mandatory) boolean, default true. Whether the value of this sub field shall get rendered or not (see next chapter).&lt;br /&gt;
&lt;br /&gt;
=== Disable rendering for a sub field ===&lt;br /&gt;
&lt;br /&gt;
When creating a subfields instance and selecting which other custom fields should be used as sub fields, you are able to select whether you want Joomla! to render this sub fields&#039; value, when the value of the parent field is being rendered. &#039;&#039;&#039;Normally, this is what you want to do,&#039;&#039;&#039; why the default value is &#039;&#039;true&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Turning this off will have consequences for sub field types for which the value, which is saved in the database, is not equal to the rendered string which is normally being used in a template: E.g. the &#039;&#039;media&#039;&#039; type which stores a path to a media file in the database, but normally renders as an &#039;&#039;&amp;lt;img&amp;gt;&#039;&#039;-tag. Turning this option off would mean that the default rendering process of the subfields field will now show the path the file instead of the &#039;&#039;&amp;lt;img&amp;gt;&#039;&#039;-tag.&lt;br /&gt;
&lt;br /&gt;
So, why does this option then even exist? Because rendering takes performance, and rendering of many sub fields of many items takes much performance and time. And this is not always what you want, nor what you need. You are basically able to switch this option off and create your own layout override for your subfields (see next chapter) - hence rendering the sub fields the way you want and saving performance by it.&lt;br /&gt;
&lt;br /&gt;
== Changing the rendering with a layout override ==&lt;br /&gt;
&lt;br /&gt;
By default, the value of all individual sub fields will be rendered and the result will be shown as a comma-separated list in the frontend. This default behavior is implemented in the file &#039;&#039;plugins/fields/subfields/tmpl/subfields.php&#039;&#039;, please take a look at it to get a first impression on how to change the rendering in general.&lt;br /&gt;
&lt;br /&gt;
The first thing to do to change the rendering is to create a layout override for that template, e.g. by creating a new file &#039;&#039;templates/$YOUR_TEMPLATE/html/plg_fields_subfields/subfields.php&#039;&#039;, see [[Layout Overrides in Joomla]] for further info.&lt;br /&gt;
&lt;br /&gt;
The next thing to do is to get an idea about the structure of the &#039;&#039;$field&#039;&#039; object that is being passed to the template. That object has 2 important properties:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;name&#039;&#039; is a string containing the name of the custom field you set.&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;subfields_rows&#039;&#039; is an array containing arrays, which contain the sub fields. So, basically, &#039;&#039;$field-&amp;gt;subfields_rows&#039;&#039; contains rows of data, and each row contains a list of sub field instances / objects. Each of those instances is a fully-featured field instance / object itself, and has properties like &#039;&#039;name&#039;&#039;, &#039;&#039;type&#039;&#039;, etc. amongst &#039;&#039;value&#039;&#039; and &#039;&#039;rawvalue&#039;&#039;, containing the rendered and unrendered value respectively.&lt;br /&gt;
&lt;br /&gt;
You can use the &#039;&#039;name&#039;&#039; property of &#039;&#039;$field&#039;&#039; to make distinctions in your template, dependent of which subfields instance is being rendered.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfields_rows&#039;&#039; property might sound a bit complicated in the first place, but when you create your own layout override and play around with it, &#039;&#039;var_dump()&#039;&#039; different states etc., you should get a good feeling about how it behaves very quickly.&lt;br /&gt;
&lt;br /&gt;
=== Example 1 ===&lt;br /&gt;
&lt;br /&gt;
Suppose we have created a custom field named &#039;&#039;ingredients&#039;&#039; for an article that contains the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;image&#039;&#039; of type &#039;&#039;text&#039;&#039; and &#039;&#039;media&#039;&#039; respectively. We now want to display those in a nice way when we are asked to render them. We could e.g. do this in the following way, note the different use of &#039;&#039;rawvalue&#039;&#039; and &#039;&#039;value&#039;&#039; here, which we use to get access to the rendered value of the &#039;&#039;media&#039;&#039; field (which is, normally, an &amp;lt;img&amp;gt; HTML tag):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php if ($field-&amp;gt;name == &#039;ingredients&#039;): ?&amp;gt;&lt;br /&gt;
  &amp;lt;ul&amp;gt;&lt;br /&gt;
    &amp;lt;?php foreach ($field-&amp;gt;subfields_rows as $row): ?&amp;gt;&lt;br /&gt;
      &amp;lt;li&amp;gt;&lt;br /&gt;
        Description: &amp;lt;?php echo htmlentities($row[&#039;description&#039;]-&amp;gt;rawvalue); ?&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
        Image: &amp;lt;?php echo $row[&#039;image&#039;]-&amp;gt;value; ?&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
  &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you could disable the rendering of the &#039;&#039;description&#039;&#039; sub field in this example (because the rendered value is not being used, only the raw value), see also previous chapter.&lt;br /&gt;
&lt;br /&gt;
=== Example 2 ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfields_rows&#039;&#039; object can get a little complicated. The following code will render all sub fields in a comma-separated list, using their &#039;&#039;rawvalue&#039;&#039; and prefixing them with their name. This example shows how the &#039;&#039;subfield_rows&#039;&#039; object can be used on a more basic-level, not using any rendered values.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &#039;&amp;lt;ul&amp;gt;&#039;;&lt;br /&gt;
foreach ($field-&amp;gt;subfields_rows as $row)&lt;br /&gt;
{&lt;br /&gt;
  echo &#039;&amp;lt;li&amp;gt;&#039;;&lt;br /&gt;
  $buffer = array();&lt;br /&gt;
  foreach ($row as $subfield)&lt;br /&gt;
  {&lt;br /&gt;
    $buffer[] = (&lt;br /&gt;
      $subfield-&amp;gt;name . &#039;: &#039;&lt;br /&gt;
      . $subfield-&amp;gt;rawvalue&lt;br /&gt;
    );&lt;br /&gt;
  }&lt;br /&gt;
  echo implode(&#039;, &#039;, $buffer);&lt;br /&gt;
  echo &#039;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
}&lt;br /&gt;
echo &#039;&amp;lt;/ul&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Custom Fields]]&lt;br /&gt;
[[Category:Beginners]]&lt;br /&gt;
[[Category:Joomla! Website Management]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Continga</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=586815</id>
		<title>Custom fields type: Subfields</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=586815"/>
		<updated>2019-01-14T23:51:08Z</updated>

		<summary type="html">&lt;p&gt;Continga: add preliminary note about feature not being in core yet&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Note ==&lt;br /&gt;
&lt;br /&gt;
The feature described on this page is not yet part of the Joomla! core. It is currently being handled as a pull request on GitHub, see https://github.com/joomla/joomla-cms/pull/22446 . This wiki page reflects the current status of that PR. This preliminary note should get removed when the PR got merged.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Custom fields in Joomla! is a technology to extend various item types (content articles, contact items, etc.) with custom-made fields, e.g. extending a content article with a text field named &#039;&#039;fact_checked_by&#039;&#039;. For a basic introduction into this topic see [[J3.x:Adding custom fields]]. &lt;br /&gt;
&lt;br /&gt;
This wiki page is an introduction into a special type for custom fields called &#039;&#039;subfields&#039;&#039;. The aim of the &#039;&#039;subfields&#039;&#039; custom field type is to provide the user the possibility to create a repeatable custom field for an item with multiple related fields, so e.g. adding a custom field named &#039;&#039;ingredients&#039;&#039; with the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;amount&#039;&#039; to a content article.&lt;br /&gt;
&lt;br /&gt;
A short note on terminology: We use the term &amp;quot;sub fields&amp;quot; to describe two different things: First, &#039;&#039;subfields&#039;&#039; is the &#039;&#039;&#039;type&#039;&#039;&#039; of the custom field that is being added to an item, so the type of the &amp;quot;parent field&amp;quot; - e.g. like other custom fields can be of type &#039;&#039;text&#039;&#039; or &#039;&#039;integer&#039;&#039;. Second, we call the configured &amp;quot;child fields&amp;quot; of that parent field &amp;quot;sub fields&amp;quot;, just because that is comfortable. An attentive reader will note the difference, but the context should always be clear what is meant. If that is not the case, we use other terms.&lt;br /&gt;
&lt;br /&gt;
== The subfields field ==&lt;br /&gt;
&lt;br /&gt;
Provides a possibility to add several (repeatable) sub fields to an item. The sub fields are each rendered by themselves and the result will by default be shown as a comma-separated list (this can be changed, see further down).&lt;br /&gt;
&lt;br /&gt;
=== Options ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;render_values&#039;&#039; (mandatory) boolean, default true.&amp;lt;br/&amp;gt;Whether the value of the sub fields should get rendered. Normally you want this to be true, unless you are using a layout override to change the overall rendering of the custom field, in which case you can disable this and slightly increase the performance when evaluating the field.&lt;br /&gt;
* &#039;&#039;repeat&#039;&#039; (mandatory) boolean, default true.&amp;lt;br /&amp;gt;Whether the sub fields should be repeatable in the backend.&lt;br /&gt;
&lt;br /&gt;
== Changing the rendering with a layout override ==&lt;br /&gt;
&lt;br /&gt;
By default, the value of all sub fields will be rendered and the result will be shown as a comma-separated list in the frontend. This default behavior is implemented in the file &#039;&#039;plugins/fields/subfields/tmpl/subfields.php&#039;&#039;, please take a look at it to get a first impression on how to change the rendering in general.&lt;br /&gt;
&lt;br /&gt;
The first thing to do to change the rendering is to create a layout override for that template, e.g. by creating a new file &#039;&#039;templates/$YOUR_TEMPLATE/html/plg_fields_subfields/subfields.php&#039;&#039;, see [[Layout Overrides in Joomla]] for further info.&lt;br /&gt;
&lt;br /&gt;
The next thing to do is to get an idea about the structure of the &#039;&#039;$field&#039;&#039; object that is being passed to the template. That object has 2 important properties:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;name&#039;&#039; is a string containing the name of the custom field you set.&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;value&#039;&#039; is an array of rows containing the rendered name + value pair for each sub field, for each occurrence (if &#039;&#039;repeatable&#039;&#039; is enabled). If you want to create a layout override, you normally won&#039;t touch this property, as it is not very flexible.&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;subfield_rows&#039;&#039; is an array of objects, whereby each object represents one row of the sub fields. Every object / row has one property for each sub field (named by the sub fields&#039; name), which again is an object with properties &#039;&#039;value&#039;&#039; and &#039;&#039;rawvalue&#039;&#039;, containing respectively the rendered and the unrendered value of that sub field for the given row.&lt;br /&gt;
&lt;br /&gt;
You can use the &#039;&#039;name&#039;&#039; property to make distinctions in your template dependent of which field is being rendered.&lt;br /&gt;
&lt;br /&gt;
Especially the &#039;&#039;subfield_rows&#039;&#039; property might sound a bit complicated in the first place, but when you create your layout override and play around with it, &#039;&#039;var_dump()&#039;&#039; different states etc. you should get a good feeling about how it behaves.&lt;br /&gt;
&lt;br /&gt;
=== Example 1 ===&lt;br /&gt;
&lt;br /&gt;
Suppose we have created a custom field named &#039;&#039;ingredients&#039;&#039; for an article that contains the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;image&#039;&#039; of type &#039;&#039;text&#039;&#039; and &#039;&#039;media&#039;&#039; respectively. We now want to display those in a nice way when we are asked to render them. We could e.g. do this in the following way, note the different use of &#039;&#039;rawvalue&#039;&#039; and &#039;&#039;value&#039;&#039; here, which we use to get access to the rendered value of the &#039;&#039;media&#039;&#039; field (which is, normally, an &amp;lt;img&amp;gt; HTML tag):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php if ($field-&amp;gt;name == &#039;ingredients&#039;): ?&amp;gt;&lt;br /&gt;
  &amp;lt;ul&amp;gt;&lt;br /&gt;
    &amp;lt;?php foreach ($field-&amp;gt;subfield_rows as $row): ?&amp;gt;&lt;br /&gt;
      &amp;lt;li&amp;gt;&lt;br /&gt;
        Description: &amp;lt;?php echo htmlentities($row-&amp;gt;description-&amp;gt;rawvalue); ?&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
        Image: &amp;lt;?php echo $row-&amp;gt;image-&amp;gt;value; ?&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
  &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Example 2 ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfield_rows&#039;&#039; object can get a little complicated. The following code will render all sub fields in a comma-separated list, just like the original template does, but it uses the sub fields&#039; &#039;&#039;rawvalue&#039;&#039; instead of the rendered value. This example shows how the &#039;&#039;subfield_rows&#039;&#039; object can be used in a more advanced way.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &#039;&amp;lt;ul&amp;gt;&#039;;&lt;br /&gt;
foreach ($field-&amp;gt;subfield_rows as $subfield_objects)&lt;br /&gt;
{&lt;br /&gt;
  echo &#039;&amp;lt;li&amp;gt;&#039;;&lt;br /&gt;
  $buffer = array();&lt;br /&gt;
  foreach (array_keys(get_object_vars($subfield_objects)) as $subfield_name)&lt;br /&gt;
  {&lt;br /&gt;
    $buffer[] = (&lt;br /&gt;
      $subfield_name . &#039;: &#039;&lt;br /&gt;
      . $subfield_objects-&amp;gt;{$subfield_name}-&amp;gt;rawvalue&lt;br /&gt;
    );&lt;br /&gt;
  }&lt;br /&gt;
  echo implode(&#039;, &#039;, $buffer);&lt;br /&gt;
  echo &#039;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
}&lt;br /&gt;
echo &#039;&amp;lt;/ul&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Continga</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=586814</id>
		<title>Custom fields type: Subfields</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Custom_fields_type:_Subfields&amp;diff=586814"/>
		<updated>2019-01-14T16:00:21Z</updated>

		<summary type="html">&lt;p&gt;Continga: Created page with &amp;quot;== Introduction ==  Custom fields in Joomla! is a technology to extend various item types (content articles, contact items, etc.) with custom-made fields, e.g. extending a con...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Custom fields in Joomla! is a technology to extend various item types (content articles, contact items, etc.) with custom-made fields, e.g. extending a content article with a text field named &#039;&#039;fact_checked_by&#039;&#039;. For a basic introduction into this topic see [[J3.x:Adding custom fields]]. &lt;br /&gt;
&lt;br /&gt;
This wiki page is an introduction into a special type for custom fields called &#039;&#039;subfields&#039;&#039;. The aim of the &#039;&#039;subfields&#039;&#039; custom field type is to provide the user the possibility to create a repeatable custom field for an item with multiple related fields, so e.g. adding a custom field named &#039;&#039;ingredients&#039;&#039; with the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;amount&#039;&#039; to a content article.&lt;br /&gt;
&lt;br /&gt;
A short note on terminology: We use the term &amp;quot;sub fields&amp;quot; to describe two different things: First, &#039;&#039;subfields&#039;&#039; is the &#039;&#039;&#039;type&#039;&#039;&#039; of the custom field that is being added to an item, so the type of the &amp;quot;parent field&amp;quot; - e.g. like other custom fields can be of type &#039;&#039;text&#039;&#039; or &#039;&#039;integer&#039;&#039;. Second, we call the configured &amp;quot;child fields&amp;quot; of that parent field &amp;quot;sub fields&amp;quot;, just because that is comfortable. An attentive reader will note the difference, but the context should always be clear what is meant. If that is not the case, we use other terms.&lt;br /&gt;
&lt;br /&gt;
== The subfields field ==&lt;br /&gt;
&lt;br /&gt;
Provides a possibility to add several (repeatable) sub fields to an item. The sub fields are each rendered by themselves and the result will by default be shown as a comma-separated list (this can be changed, see further down).&lt;br /&gt;
&lt;br /&gt;
=== Options ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;render_values&#039;&#039; (mandatory) boolean, default true.&amp;lt;br/&amp;gt;Whether the value of the sub fields should get rendered. Normally you want this to be true, unless you are using a layout override to change the overall rendering of the custom field, in which case you can disable this and slightly increase the performance when evaluating the field.&lt;br /&gt;
* &#039;&#039;repeat&#039;&#039; (mandatory) boolean, default true.&amp;lt;br /&amp;gt;Whether the sub fields should be repeatable in the backend.&lt;br /&gt;
&lt;br /&gt;
== Changing the rendering with a layout override ==&lt;br /&gt;
&lt;br /&gt;
By default, the value of all sub fields will be rendered and the result will be shown as a comma-separated list in the frontend. This default behavior is implemented in the file &#039;&#039;plugins/fields/subfields/tmpl/subfields.php&#039;&#039;, please take a look at it to get a first impression on how to change the rendering in general.&lt;br /&gt;
&lt;br /&gt;
The first thing to do to change the rendering is to create a layout override for that template, e.g. by creating a new file &#039;&#039;templates/$YOUR_TEMPLATE/html/plg_fields_subfields/subfields.php&#039;&#039;, see [[Layout Overrides in Joomla]] for further info.&lt;br /&gt;
&lt;br /&gt;
The next thing to do is to get an idea about the structure of the &#039;&#039;$field&#039;&#039; object that is being passed to the template. That object has 2 important properties:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;name&#039;&#039; is a string containing the name of the custom field you set.&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;value&#039;&#039; is an array of rows containing the rendered name + value pair for each sub field, for each occurrence (if &#039;&#039;repeatable&#039;&#039; is enabled). If you want to create a layout override, you normally won&#039;t touch this property, as it is not very flexible.&lt;br /&gt;
* &#039;&#039;$field-&amp;gt;subfield_rows&#039;&#039; is an array of objects, whereby each object represents one row of the sub fields. Every object / row has one property for each sub field (named by the sub fields&#039; name), which again is an object with properties &#039;&#039;value&#039;&#039; and &#039;&#039;rawvalue&#039;&#039;, containing respectively the rendered and the unrendered value of that sub field for the given row.&lt;br /&gt;
&lt;br /&gt;
You can use the &#039;&#039;name&#039;&#039; property to make distinctions in your template dependent of which field is being rendered.&lt;br /&gt;
&lt;br /&gt;
Especially the &#039;&#039;subfield_rows&#039;&#039; property might sound a bit complicated in the first place, but when you create your layout override and play around with it, &#039;&#039;var_dump()&#039;&#039; different states etc. you should get a good feeling about how it behaves.&lt;br /&gt;
&lt;br /&gt;
=== Example 1 ===&lt;br /&gt;
&lt;br /&gt;
Suppose we have created a custom field named &#039;&#039;ingredients&#039;&#039; for an article that contains the sub fields &#039;&#039;description&#039;&#039; and &#039;&#039;image&#039;&#039; of type &#039;&#039;text&#039;&#039; and &#039;&#039;media&#039;&#039; respectively. We now want to display those in a nice way when we are asked to render them. We could e.g. do this in the following way, note the different use of &#039;&#039;rawvalue&#039;&#039; and &#039;&#039;value&#039;&#039; here, which we use to get access to the rendered value of the &#039;&#039;media&#039;&#039; field (which is, normally, an &amp;lt;img&amp;gt; HTML tag):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php if ($field-&amp;gt;name == &#039;ingredients&#039;): ?&amp;gt;&lt;br /&gt;
  &amp;lt;ul&amp;gt;&lt;br /&gt;
    &amp;lt;?php foreach ($field-&amp;gt;subfield_rows as $row): ?&amp;gt;&lt;br /&gt;
      &amp;lt;li&amp;gt;&lt;br /&gt;
        Description: &amp;lt;?php echo htmlentities($row-&amp;gt;description-&amp;gt;rawvalue); ?&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
        Image: &amp;lt;?php echo $row-&amp;gt;image-&amp;gt;value; ?&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
  &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Example 2 ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;subfield_rows&#039;&#039; object can get a little complicated. The following code will render all sub fields in a comma-separated list, just like the original template does, but it uses the sub fields&#039; &#039;&#039;rawvalue&#039;&#039; instead of the rendered value. This example shows how the &#039;&#039;subfield_rows&#039;&#039; object can be used in a more advanced way.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &#039;&amp;lt;ul&amp;gt;&#039;;&lt;br /&gt;
foreach ($field-&amp;gt;subfield_rows as $subfield_objects)&lt;br /&gt;
{&lt;br /&gt;
  echo &#039;&amp;lt;li&amp;gt;&#039;;&lt;br /&gt;
  $buffer = array();&lt;br /&gt;
  foreach (array_keys(get_object_vars($subfield_objects)) as $subfield_name)&lt;br /&gt;
  {&lt;br /&gt;
    $buffer[] = (&lt;br /&gt;
      $subfield_name . &#039;: &#039;&lt;br /&gt;
      . $subfield_objects-&amp;gt;{$subfield_name}-&amp;gt;rawvalue&lt;br /&gt;
    );&lt;br /&gt;
  }&lt;br /&gt;
  echo implode(&#039;, &#039;, $buffer);&lt;br /&gt;
  echo &#039;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
}&lt;br /&gt;
echo &#039;&amp;lt;/ul&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Continga</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=User:Continga&amp;diff=586813</id>
		<title>User:Continga</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=User:Continga&amp;diff=586813"/>
		<updated>2019-01-14T13:56:03Z</updated>

		<summary type="html">&lt;p&gt;Continga: This is my new user page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;My name is Continga and if you want to get in touch with me, post on my &#039;&#039;&#039;[[User_talk:{{PAGENAME}}|talk page]]&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
==My testing subpages==&lt;br /&gt;
&amp;lt;splist/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Continga</name></author>
	</entry>
</feed>