Hi, I'm trying to create a computed field based on other properties. The setup is:
Document Type "ingredient" - "name"
Element Type "ingredient list item" - "quantity, scale, ingredient(content picker)"
On the Element type, how do I create a computed field that is a formatted version of the other fields? The end result should be something like "${quantity}{scale} - {ingredient.name}"
To create a computed field in Umbraco 9 that is a formatted version of other fields, you can use the Computed Field property editor. Here's how you can achieve the desired result:
Navigate to the Document Type "ingredient" in the Umbraco backoffice.
Locate the Element Type "ingredient list item" and open it for editing.
Add a new property of type "Computed Field" to the "ingredient list item" Element Type. Let's call it "formattedIngredient" for this example.
In the "Expression" field of the "formattedIngredient" property, you can write the code to compute the desired value. Use the following syntax:
This expression concatenates the values of the "quantity" and "scale" fields with the "ingredient.name" field, separated by " - ".
Save the changes to the Element Type.
Now, whenever you create or update an "ingredient list item" content item, the "formattedIngredient" field will automatically compute its value based on the values of the other fields.
Make sure to adjust the expression according to your specific field names and formatting requirements. Also, remember to save and publish your changes to see the computed field in action.
Please note that the Computed Field property editor might have some variations depending on the version of Umbraco you are using.
If you're looking for a way to do this (for display purposes), the Render Macro property editor in Contentment could be used — it lets you use a macro for rendering a value to display for a property (but doesn't store it).
The macro has the usual access to Content etc. so you can compute a display value and render it alongside all other properties.
Computed label based on document type properties
Hi, I'm trying to create a computed field based on other properties. The setup is:
On the Element type, how do I create a computed field that is a formatted version of the other fields? The end result should be something like "${quantity}{scale} - {ingredient.name}"
Thanks in advance.
A solution/work around was found by a team member.
Using the label of block in a Block List:
{{ quantity }}{{ scale }} - {{ ingredient | ncNodeName}}
To create a computed field in Umbraco 9 that is a formatted version of other fields, you can use the Computed Field property editor. Here's how you can achieve the desired result:
Navigate to the Document Type "ingredient" in the Umbraco backoffice. Locate the Element Type "ingredient list item" and open it for editing. Add a new property of type "Computed Field" to the "ingredient list item" Element Type. Let's call it "formattedIngredient" for this example. In the "Expression" field of the "formattedIngredient" property, you can write the code to compute the desired value. Use the following syntax:
${quantity} + ${scale} + " - " + ${ingredient.name}
This expression concatenates the values of the "quantity" and "scale" fields with the "ingredient.name" field, separated by " - ".
Save the changes to the Element Type. Now, whenever you create or update an "ingredient list item" content item, the "formattedIngredient" field will automatically compute its value based on the values of the other fields.
Make sure to adjust the expression according to your specific field names and formatting requirements. Also, remember to save and publish your changes to see the computed field in action.
Please note that the Computed Field property editor might have some variations depending on the version of Umbraco you are using.
Sorry, Do you have a real example? We don't understand how to you do this. Thanks.
Hi Biagio,
If you're looking for a way to do this (for display purposes), the Render Macro property editor in Contentment could be used — it lets you use a macro for rendering a value to display for a property (but doesn't store it).
The macro has the usual access to Content etc. so you can compute a display value and render it alongside all other properties.
Hope that helps,
/Chriztian
Where is Computed Field property editor?
The "Computed Field" is a hallucination from ChatGPT. The field doesn't exist.
is working on a reply...