Advanced Editor

This feature allows OTRS administrators and OTRS developers with experience using Template Toolkit to write Template Toolkit code snippets in OTRS templates. This can facilitate, for example, the customization of response templates with multiple languages because you can customize the same template for many languages by using conditions without adding completely new response templates. This saves resources within OTRS and gives you a cleaner overview of your response templates.

This feature extends the standard editor by enabling logical if-else conditions as well as loops and much more.

To insert code snippets:

  1. Go to the System Configuration screen.

  2. Search for the setting AdvancedEditor and enable it.

  3. Open Templates, Signatures or Salutations modules in the administrator interface.

  4. Add or modify a resource in these screens.

  5. Find the new icon in the Rich Text editor toolbar (the last one).

    Insert Code Snippet Icon

    Insert Code Snippet Icon

  6. Click on the new icon to open a new window.

  7. Select TemplateToolkit from the Language drop-down.

  8. Write the following lines into the text box.

    [% IF ( matches = Data.CustomerUser.UserLanguage.match('^de') ) %]
    Sehr geehrte(r) [% Data.CustomerUser.UserFirstname %] [% Data.CustomerUser.UserLastname %],<br />
    [% ELSIF ( matches = Data.CustomerUser.UserLanguage.match('^hu') ) %]
    Tisztelt [% Data.CustomerUser.UserLastname %] [% Data.CustomerUser.UserFirstname %]!<br />
    [% ELSE %]
    Dear [% Data.CustomerUser.UserFirstname %] [% Data.CustomerUser.UserLastname %],<br />
    [% END %]
  9. Click on the OK button to save the code snippet.

    Rich Text Editor Code Snippet

    Rich Text Editor Code Snippet

  10. Click on the Save or Save and finish button.

  11. Add the template, signature or salutation to the queue you want to use it.

  12. Create a new ticket, choose a customer user (for this example we will call him John Doe), then choose the queue you have configured your template for.

If the customer user language is German, it should print Sehr geehrte(r) John Doe,. If it is set to Hungarian, you should see Tisztelt Doe John!. If your customer user has no language set or it is set to English, you will see Dear John Doe,.

As you can see, conditions in templates can be very useful, but be careful to write correct Template Toolkit syntax. If you make mistakes there, you will get an error during choosing a template.

See also

For detailed instructions on how to write Template Toolkit code, refer to the Template Toolkit User Manual.

Debugging Templates

Writing Template Toolkit code is not too difficult compared to other languages. Nevertheless errors can occur as we are all just humans.

If you have mistakes in your Template Toolkit syntax, saving a template will bring up an error screen that tell you about what went wrong and where to find the error.

Error Reason in Error Screen

Error Reason in Error Screen

In this example the OTRS system informed us, that there was an unexpected token [ in the line [% IF Data.OTRSTagData.TypeID == 1 [% %]. A second opening bracket was entered inside the same Template Toolkit tag, which for sure is forbidden.

To fix the error:

  1. Go back to the previous page.

  2. Edit the template and save it.

  3. Repeat these steps until no more errors are found.

Scroll to Top