Formulas in Documents


In DocketManager versions 3.11+, it is possible to use formulas in combination with Document HTML Tags. This provides for a greater amount of versatility because it allows you to return values that are the result of more complex operations. Formulaic operations are performed on a tag or a combination of multiple tags in conjunction with helpers.


For an introduction to and overview of helpers, see: http://assemble.io/helpers/

For a list of of Custom Helper Functions contained in DocketManager, see: HTML Document Handlebars/JavaScript Helper Functions


Important to note: When working with the Assemble IO formulas, the values being used have to exist. If not, the created document will generate an error. You can get around this by using if statements, and making sure values exist, before running the code that will fetch the values and perform an operation.


When you are looking to combine helper functions, i.e. you want to divide two values and then set the resulting value’s precision to two decimal places, this can be achieved by using parenthesis.


Example:

 {{toFixed (divide Quantity Outs) 2}}. 


That is saying divide quantity by outs(ups) and then take that resulting value and make sure its set to a fix precision of two decimal places. The entire operation can be put in a single set of double curly braces but the differing operations need to be separated by parenthesis.


Example:

<!--{{#each OrderItems}}-->
<!--{{#if Outs}}-->
{{toFixed (divide Quantity Outs) 2}}
<!--{{/if}}-->
<!--{{/each}}-->


Example for a job that requires dividing the quantity by outs:

Postcard - 5x7 - Black/0-Bleed
500 Quantity 1
125 Sheets For Cost, 125 Sheets For Price
12 x 18 Run Size
5 x 7 Flat Size
5 x 7 Finish Size
4 Up, 1 On, 1 Sheets, 1 Pages, 1 Multipart
0 Overs


The snippet of code created would be:

{{#withSort Orders "OrderNumber" sortBy="asc"}}
{{toFixed (divide Quantity Outs) 2}}
{{/withSort}}


The result is 125.


Assemble Helpers resource links:

Math [http://assemble.io/helpers/helpers-math.html]
Numbers [http://assemble.io/helpers/helpers-numbers.html]

Additional helpful links: https://github.com/helpers/handlebars-helpers/tree/master/lib