OL Learn

Various Tips & Tricks for Connect Designer

This article encompasses “small” tips & tricks that can help users like you get to where you’re going in Connect Designer.

UPDATE: Most of these tricks, and more, can now be accessed through the How-to section on Learn. No more tricks will be added to this page.

1 Like

Making variables or functions global in Connect’s “Scripts” pane

This trick is probably for advanced scripting users, and only refers to the editable, full scripts (not to text script wizards or dynamic image wizards, for instance). Since each script in the Scripts pane is a separate environment, declaring a variable or a function using the var keyword, it will only be accessible from within the script itself.

The magic trick if you hadn’t guessed it: omit the var keyword! By doing this, functions and variables that are declared in this script will be available to any script run after it.

Some limitations:

  • Any use of the variables and functions in other scripts currently displays an error, indicating that it’s not defined. This error will be corrected in a future version, so it should only happen in version 1.0.0 of PlanetPress Connect.
  • This method is only for editable Scripts.
  • Global variables must be declared in a script that appears before they are used - I generally have a script called “Globals” as the very first script in the Scripts pane.

Oh, and here’s a sample that implements this trick!

Using JSON Data in templates

I love JSON. It’s a simple data exchange format that’s extendable, simple to write, and really, really easy to parse when you’re in an HTML/CSS/Javascript environment. I generally use it to transfer small bits of data between PlanetPress Workflow and Connect Designer through the DataMapper using a singe local variable (see the tip on doing that on this page).

So let’s say you have a JSON string that looks like: {"authenticated": true, "username": "Evie", "sessionid": "2345LKTJ345HOIJEW450"} , and this indicates to your template that a user is logged in and to show the “logout” button, the username, etc. This is set to the user_data variable in Workflow, passed on through datamapper into the data model used in the Designer module, with the field name user_data.

To use this data you’ll need a script. Let’s say I want to extract the username. The script would look like this (say, on a #username selector for the div with that ID):

var user_data = JSON.parse(record.fields.user_data);

It’s as simple as that! The fields in user_data are available with dot notation so you can do a condition like if(user_data.authenticated) { do something }; and that will work because “authenticated” is a real true/false value.

Using loadjson()

Another method to use JSON is to load that JSON data directly from an external location. This location can be:

  • A local file on the drive
  • An external URL such as an online service
  • A PlanetPress Workflow process that returns JSON data.

The loadjson() function is available in the Designer module, in scripts. It simply requires the URL or path to the JSON file:

var json_variables = loadjson(“file:///c:/jsondata/variables.json”);
var json_users = loadjson(“http://www.example.com/api/getusers/all”);

Accessing the data inside those variables will be the same as the example above - you could just access json_variables.base_url , for example.

For more information on JSON data, check out Wikipedia: JSON.

Selecting a PDF Page Number

So you want to be able to select a specific page number from a PDF resource in your template? You want to do this either statically or dynamically? Look no further. The trick is super simple: ?page=N

Yes, that’s right, you just add a that to the end of your image’s Source (“src” attribute) and you’re golden! This can be from the Attributes pane in the Source box (images/myfile.pdf?page=3) or in a script (results.attr("src", "images/myfile.pdf?page=" + record.fields.pagenum); ). Of course this can only be dynamic using a script, but as you can see this particular one is not super complicated.

Oh and yes, this also works from external resources (see the Internal, External and Web resources tip!), but not for Web resources (at least not at the moment).


the Link “http://help.objectiflune.com/files/connect-samples/Sample-Using-Global-VariablesAnd-Functions.OL-template” seems to be invalid.

I get an HTTP 404 -error page.

Wooops! My apologies, I forgot to copy these files over after a minor migration. They have been placed back in their appropriate location.

Hanging indents for signature images

With a hanging indent the second and following lines are indented more than the first line. This makes the first line stick out to the left. This technique can also used to place an inline signature image beyond the normal margin lines.

To make a signature image hang outside the flow:

  1. Add a signature image to the Image resources of your template (e.g. drag and drop from the file system).
  2. Insert an empty paragraph to your document.
  3. Drag and drop the image to the empty paragraph.
  4. Right mouse click the image and select Paragraph in the contextual menu.
  5. Enter a negative value in the First Indent field.