0 comment(s).

Interpolated local/server code

You may include pieces of programming code in your snippet text, that will be executed upon insertion and returning value will be actually used as a part of snippet contents (therefore inserted into document as well). They are enclosed in ` - a backstick character. There are two types of code that might get executed. Local and server codes. Local code is a piece of JavaScript, server code performs action on server side (by calling external remote method, that must exists and is not included in the snippet code). Let's see some examples of this (please note, you can insert as many interpolated codes into snippet defition as you want):

Local code:

Hello, today is `/local/javascript
        // this is a regular JavaScript code, you can do whatever you want, jus make sure you fill the "output" variable with some result.
        output = new Date();
`.

Server code (please note the escape of variables - by prepending $ the variable value is properly escaped):

Reversed string is: `/remote/post
        action = 'reverse_string';
        params.str = '$$CHAP_PREV_WORD';
`.

Preceding example takes word before caret, sends it to the reverse_string remote method (which is executed on a server), waits for returned reversed string and includes it into the snippet text (after Reversed string is: ). This newly created snippet text is then inserted into the document.

We just scratch the surface, but you can already see how vivid the snippet platform already is - by adding dynamic scripting, the sky is the limit :-). And we are not finished with snippets yet.