Note-to-myself:
- Make the xyz.soy file. First line should contain {namespace namespace_name} defining a name for your namespace.
- Define function calls inside the soy file using the format below, replacing abc with your HTML template and code:
/**
* function_name function description
* @param? param1 description
* @param param2 description
*/
{template .function_name}
<templating code>
{/template}
- Compile the xyz.soy file into a .js file using the following command (You’ll need java runtime installed. I used Sun’s jre 6):
java -jar [path_to_Closure_folder]/SoyToJsSrcCompiler.jar –outputPathFormat ‘[filename_format].js’ xyz.soy
You can get more details about what can be used in outputPathFormat here.
- Import the generated javascript code file and the soyutils.js into your html file (before the main.js where templating functions will be called):
<script type=”text/javascript” src=”script/[path_to_Closure_folder/]soyutils.js”></script>
<script type=”text/javascript” src=”script/[generated_js_filename].js”></script>
- Call the templating functions as namespace_name.function_name(params) from anywhere in main.js or the HTML code.
- Done :)
Refer to:
Now, done.
P.S.: Finally finished moving the code through Closure templates. Now can begin normal development again.