I've created a document type called Project and have among other things added two numeric properties called Rate per hour and Estimated hours.
So far so good.
But I now I want to multiplicate the content of these properties and output the result in the document type. I realise that I probably need to add another property to do the math and the output. What's the easiest way to accomplish this?
For such an easy equation as {{hours}}*[[rate}} it seems overly complicated to need to add both a manifest, controller and view files.
Thanks for your reply.
Actually the brackets were more to illustrate the simplicity of what I needed to do.
More likely I'd like to paste code like:
@{
var result = hours*rate;
}
Profit: @result
How can I paste code like this in the document type view? Is the only way to create a new property?
Personally I'd create an editor to store both values and output the calculated product - you'd then have hours and rate both in the same scope, rather than having to fetch them from other properties.
Thanks for your reply. I'm aware of this possibility, but then we're back to having to create both manifest, controller and view files. Something that seems overly complicated just to be able to insert basically one line of code.
For a system that otherwise is so flexible in building the tabs of the document types it seems crazy that there wouldn't be an easier way to implement custom code.
I take your point, but you'll find that adding your own packages makes Umbraco even more flexible - for the sake of a couple of files, you can build out custom editors really easily.
Also gives you the scope to extend the output in future. For your example, there might be a future need to include currency conversions (strange example, I know), which would be easy to implement inside your custom editor.
Correct. I'm pretty new to Umbraco so my description might not have been clear on that.
Still, I would have expected a simpler way. For example a standardised custom code property into which you could insert the lines of code.
I guess I have to get more familiar with creating own packages.
Thanks!
OK, perhaps I just need to get more familiar with creating my own packages.
But let's extend my example. Let's say I have a document type called Customer and a document type called Events.
I want to use the Umbraco admin as the primary work surface, instead of a frontend. So in the document type edit view for Customer I want to have a calendar listing instances of Events. Should I build the calendar as a new property as well, or is there a better way considering it will have dependencies from external files (ie jQuery UI)?
Thanks to the replies Markus and Nathan. I followed Nathan's advice and stored the values for Hours and Rate in the same editor, making it easy to execute and print the result of the equation within the same scope.
My document type Customer, with the tab Projects, containing nested content of the document type Project now looks like this:
Simple multiplication
I've created a document type called Project and have among other things added two numeric properties called Rate per hour and Estimated hours. So far so good. But I now I want to multiplicate the content of these properties and output the result in the document type. I realise that I probably need to add another property to do the math and the output. What's the easiest way to accomplish this? For such an easy equation as {{hours}}*[[rate}} it seems overly complicated to need to add both a manifest, controller and view files.
Hi David!
From the brakets that you had in your example I'm guessing that you are talking about a AngularJS-view?
In that case this should work: {{hours * rate}}
Or you could use a method on your scope, something like {{amount()}}
And then:
Thanks for your reply. Actually the brackets were more to illustrate the simplicity of what I needed to do. More likely I'd like to paste code like: @{ var result = hours*rate; }
Profit: @result
How can I paste code like this in the document type view? Is the only way to create a new property?
Personally I'd create an editor to store both values and output the calculated product - you'd then have hours and rate both in the same scope, rather than having to fetch them from other properties.
Thanks for your reply. I'm aware of this possibility, but then we're back to having to create both manifest, controller and view files. Something that seems overly complicated just to be able to insert basically one line of code. For a system that otherwise is so flexible in building the tabs of the document types it seems crazy that there wouldn't be an easier way to implement custom code.
Hi!
Ahh, are you looking to do the calculation in the accual content type (aka document type) edit view?
Then you only option is a custom property editor - I would not say that this is hard just 3 file and 10-15 lines of code.
// m
I take your point, but you'll find that adding your own packages makes Umbraco even more flexible - for the sake of a couple of files, you can build out custom editors really easily.
Also gives you the scope to extend the output in future. For your example, there might be a future need to include currency conversions (strange example, I know), which would be easy to implement inside your custom editor.
Correct. I'm pretty new to Umbraco so my description might not have been clear on that. Still, I would have expected a simpler way. For example a standardised custom code property into which you could insert the lines of code. I guess I have to get more familiar with creating own packages. Thanks!
OK, perhaps I just need to get more familiar with creating my own packages. But let's extend my example. Let's say I have a document type called Customer and a document type called Events. I want to use the Umbraco admin as the primary work surface, instead of a frontend. So in the document type edit view for Customer I want to have a calendar listing instances of Events. Should I build the calendar as a new property as well, or is there a better way considering it will have dependencies from external files (ie jQuery UI)?
Hi David!
It's great that you have found Umbraco =D
I really don't understand why you would want to summeries the rate and hours in the document type editor?
I would think that this is something you would like to do in the accual edit-view for the node in the content section?
A property editor is quite simple to create, you can use this as a starting point: https://github.com/enkelmedia/Umbraco7-SeoVisualizer
If you would like to kickstart your work with Umbraco I can recommend my official Umbrac-courses in Swedish: http://www.enkelmedia.se/vi-erbjuder/utbildning-umbraco.aspx
For this task "Extending the backoffice" would be the right course.
Thanks to the replies Markus and Nathan. I followed Nathan's advice and stored the values for Hours and Rate in the same editor, making it easy to execute and print the result of the equation within the same scope. My document type Customer, with the tab Projects, containing nested content of the document type Project now looks like this:
Thanks again!
Looks great, nice job.
I'm a huge fan of building custom editors, even for simpler tasks - anything that makes life easier for content editors is worth doing, in my opinion.
Looks great! I agree with Nathan - custom editors rocks =D
Nice one David.
Im actually doing something similar my self, and i actually got stuck at the same problem as you had :-). Keep up the good work!
Many Regards
Mikael S
On to the next thing; building a calendar in the admin, listing posts of a certain document type. Might come another cry for help soon...
is working on a reply...