Custom fields view customization¶
The most interesting feature of the Extended Fields plugin is, perhaps, templating. With templates you can control how the value of a custom field is rendered.
Customize by custom field type¶
To specify a template for custom fields of a particular type create file _<type>.html.erb
in the app/views/custom_values/common
directory.
The following table contains the list of currently existing (known) custom field types:
Identifier | English name | Provided by |
---|---|---|
string |
Text | core |
text |
Long text | core |
int |
Integer | core |
float |
Float | core |
list |
List | core |
date |
Date | core |
bool |
Boolean | core |
user |
User | Redmine 1.2.x |
version |
Version | Redmine 1.2.x |
link |
Link | this plugin |
wiki |
Wiki text | this plugin up to 0.2.2 |
project |
Project | this plugin |
Sample file¶
The following file will display a value of a boolean custom field as a checkbox:
<%= check_box_tag(custom_field.custom_field.name, '1', custom_field.true?) %>
The filename should be app/views/custom_values/common/_bool.html.erb
.
Customize by custom field name¶
Templates can be specified for custom fields based on their type and name. For this the file should have name _<custom_field_name>.html.erb
and be located in the <type>
subdirectory under the app/views/custom_values
directory.
The filename should contain only latin lower case characters, numbers and underscores... Custom field names are unlikely to meet this format. So the plugin “converts” the name into the filename format by replacing all non-latin characters and non-numbers by underscores (e.g. filename for “Very Cool Custom Field” should be _very_cool_custom_field.html.erb
).
Sample file¶
The following file will display a value of custom field “Complexity” as a progress bar:
<%= progress_bar(custom_field.value.to_i, :width => '80px', :legend => "#{custom_field.value}%") %>
The filename should be app/views/custom_values/int/_complexity.html.erb
.
Available variables¶
The plugin passes CustomValue
instance with the name custom_field
to the template. The following data (some of them) are available in this variable:
Variable | Sample value | Meaning |
---|---|---|
custom_field.custom_field |
CustomField instance |
|
custom_field.custom_field.type |
UserCustomField |
Type of custom field/customized object |
custom_field.custom_field.name |
Name of custom field | |
custom_field.custom_field.field_format |
string |
Field format |
custom_field.custom_field.default_value |
Default value | |
custom_field.customized |
Customized object e.g. User instance |
|
custom_field.value |
Field value | |
custom_field.true? |
Check if field value evaluates to true |
|
custom_field.visible? |
Is custom field visible | |
custom_field.customized_type |
Project |
Type of customized object |