codemonauts / craft-unit-field
Craft CMS plugin to add a field with a range of values and predefined units of measurement.
Installs: 2 299
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Type:craft-plugin
Requires
- php: ^8.0
- craftcms/cms: ^4.0.0
This package is auto-updated.
Last update: 2025-03-06 21:01:50 UTC
README
This field allows you to enter two values as range and selecting a predefined unit of measurement. Perfect to store dimensions or other ranges of values for products.
Requirements
- Craft CMS >= 4.0.0
Installation
Open your terminal and go to your Craft project:
cd /path/to/project
composer require codemonauts/craft-unit-field
./craft install/plugin unitfield
Plugin Settings
In the settings you can define all available units of measurement. You can also group units to easier select them later.
Field Settings
In every field you can set a default unit of measurement and a Twig template to render the table cells in the index of entries.
Input
The input field has two text inputs for the minimum and maximum value and a dropdown to choose the unit of measurement.
Usage in templates
In templates you can access the minimum and maximum values as well as the unit value and the corresponding label:
{{ entry.myField.min }} to {{ entry.myField.max }} {{ entry.myField.unitLabel }}
Translation
All label can be translated. Use a translation file named unitfield.php
in the language's translation directory.
With ❤ by codemonauts