Managing Docxpresso Resources

Docxpresso Resources are designed to simplify template processing and edition.

You may create the following type of resources:

  • Lists that may feed dropdown menus.
  • RPCs that allow the template to access external data via AJAX JSONP requests.
  • Custom validations

Lists

Custom lists may be created to populate dropdown menus integrated within the template.

Imagine, for example, that your document requests from a end user to introduce his country of birth, Docxpresso offers you the possibility to create an automatic list of key value pairs with the corresponding country names and their corresponding ISO codes (beware that the stored value in the generated document will never be the key but its ssociated value).

One may create these lists that can be used and reused in different templates directly from the Docxpresso backoffice interface, a somehow tedious process for long ones or using TSV (Tab Separated Values) or JSON that can be easily created in any plain text editor.

If you wish to upload any of these two formats you should do the following:

  1. Click on the wrench icon located at the left of the header of the Data: key-value pairs box.
  2. Choose your favourite format from the dropdown menu (notice that if you do not clean first the list the inserted values will be added at the end of the list)
  3. Insert the TSV or JSON string in the textarea input boxes following the suggested format (otherwise the list item will not be rendered).

RPCs

You may easily setup a call to a RPC from the Docxpresso interface.

Beware that although you can implement security measures (the call by AJAX incorporates an APIKEY that may be validated) we recomend this method only to send data that may not pose security risks (you may use the requestDataURI parameter to recall directly data from the server via a secure cURL method).

You are responsible of setting the RPC method in the remote server to serve a padded JSONP answer with the following structure that we will illustrate by way of example.

First notice that Docxpresso will check if the required parameters (set in the Docxpresso RPC interface) are sent by GET in the HTTP request and otherwise will prompt the end user to introduce the required value.

This simple RPC will populate the template variable "idnumber" sinply echoing the requested "id" parameter (not very useful but illustrative enough):

<?php 
header('Content-type: text/javascript');
$id = $_GET['id'];
$callback = $_GET['callback'];
$json='{"varValues":{"idnumber": ["' . $id .'"]}}';
echo $callback . '(' . $json . ')';

Notice that the JSON format should comply with the native Docxpresso JSON format.

It is important to note that you may concatenate RPCs calls, for example you may load catalog items and load the prices of the chosen items on real time via a triggered RPC (check the backoffice RPC interface).

Custom validations

Custom validations can be created in two flavours:

  • Date or
  • Regular expression

The Date as it seems obvious from its name is specialized in custom date formatting. In this case the date format must be a combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy, e.g. dd/mm/yyyy or DD MM dd, yyyy

  • d, dd: Numeric date, no leading zero and leading zero, respectively, e.g. 2, 02.
  • D, DD: Abbreviated and full weekday names, respectively, e.g. Mon, Monday.
  • m, mm: Numeric month, no leading zero and leading zero, respectively, e.g. 4, 04.
  • M, MM: Abbreviated and full month names, respectively, e.g. Jan, January
  • yy, yyyy: 2- and 4-digit years, respectively, e.g. 15, 2015.

If you want to use the reserved chars: D, M, Y, d, m and as plain text you should include instead their corresponding HTML entities, namely: &#68;, &#77;, &#89;, &#100;, &#109; and &#121; respectively.

For example a spanish date of the format 07 de 01 de 2013 will need the following validation expression dd &#100;e mm &#100;e yyyy.

In the general case, i.e. regular expression you just need to include a standar regex without delimiters and scaping non-alpjhanumeric characters.

For example the expression ^[0-9]{6,8}\-[A-Z]{1}$ should be included to parse a typical ID of the form 1234567-B.