I believe its the namespace
twig template function - and fields typically use the default namespace as fields
. This is defined under templates/_includes/fields.html
Looking at that file (below), you'll notice that if you don't provide a namespace
variable to the include, it'll use fields
.
{% if element is not defined %}{% set element = null %}{% endif %}
{% if namespace is not defined %}{% set namespace = 'fields' %}{% endif %}
{% namespace namespace %}
{% for field in fields %}
{% include "_includes/field" with {
field: field.getField(),
required: field.required,
element: element,
static: (static is defined ? static : null)
} only %}
{% endfor %}
{% endnamespace %}
In another scenario, you might have the following in your regular templates:
{% namespace 'myNamespace' %}
<input id="test" name="test">
<input id="another-test" name="another-test">
{% endnamespace %}
Which would produce the equivalent, rendered HTML of:
<input id="myNamespace-test" name="myNamespace[test]">
<input id="myNamespace-another-test" name="myNamespace[another-test]">
Its particularly useful in plugins or other complicated field handling where you don't have to worry about settings up name attributes (heaven forbid you have to change all your field name attributes with lots of fields!). This way, you can easily provide a wrap of context to your fields, while keeping the form elements pretty lean.
Another important factor is the ID generation, which also flows onto labels for field - useful for accessibility.
In PHP, this is done with the TemplatesService::namespaceInputs
method...
craft()->templates->namespaceInputs($element, $namespace);
You can read a detailed breakdown of how this method works in the class reference docs...