Example custom functions

Creating a custom interface for a question

Suppose you allow your end-users to choose the legal entity for which the contract is being composed. Besides changing the address, VAT number, etc. this would also change the logo in the header of the document.

While ClauseBase’s standard tools allow you to predefine a list of entities, and then insert the relevant logo into the document’s header, the logo will not be visible towards the end-users until the document is effectively exported to DOCX / PDF (because headers and footers are deliberately not shown within the browser).

Using a “custom block” question and some Clojure code, you can however easily show this logo within the list of questions.

  • Create a question with text-answers that has three predefines: “Microsoft”, “Google” and “Apple”. Assign identifier “entity” to this question.
  • Create a “custom block” question.

Insert the following code into the custom block’s code box:

(when-let [entity-name  (answer "entity")]
  [:img {:style {:padding "10px"}
         :width "200px"
         :src (case entity-name
                 "Microsoft" "https://bit.ly/2MhZegg"
                 "Google" "https://bit.ly/2TWJwvp"
                 "Apple" "https://apple.co/3gEE4XE")}])
  • This code only shows something on the screen when the answer to the question with identifier entity is set (i.e., when one of the three entities is chosen).
  • The code uses so-called “Hiccup-style” Clojure-code for creating user interfaces in a browser (see an in-depth introduction). It essentially creates:
    • an image HTML-component
    • with a 10px style padding and a fixed width of 200px
    • with a reference to a URL that depends on the entity-name chosen

The results is as follows:

Was this article helpful?
Dislike
Custom functions