Create flexible templates for Google Docs and generate instances of your templates using a sidebar GUI. See the demo video here
🔤 Variables: Define variables and replace them with strings using text inputs in the GUI
✅ If Statements: Define conditional blocks of content in your document and show/hide them using checkboxes in the GUI
💱 Switch Statements: Define conditional blocks of content for more than two scenarios and show/hide them using dropdowns in the GUI
🖇Nesting: You can use variables inside of if or switch statements
💫 Flexible: DTL can be used to create anytype of document template you want
As of now, DTL isn't published as an add-on. So you need to create your own Apps Script project by copying this file.
git clone https://github.com/YTolun/dtl.git
Create a Google Doc file in youy Drive and open the Script Editor by going to Tools > Script Editor
To learn the Script Id of your newly created Google Doc, open the Script Editor and go to File > Project Properties
Copy the Script Id of your Google Doc and change /.clasp.json
accordingly.
Please follow the instructions on clasp README to install clasp, log into it and turn on your Apps Script API.
Run
clasp push
Now when you open your Google Doc, you'll see the DTL item on the menu.
You can use this JSX-inspired syntax anywhere in your document to manipulate your template using the generated sidebar UI.
Variables control string values and they're represented by text inputs in the GUI. There are two ways of defining a variable in DTL.
Regular print tag:
<dtl:print={variableName} />
Shorthand tag (better suited for inline usage):
<dtl={variableName} />
If statements control blocks of elements that you wish to show or hide depending on a boolean variable. If statements are represented by checkboxes in the GUI.
If statement syntax:
<dtl:if={booleanName}>
This block of text will only be included in the generated copy of the document
if the booleanName is set to true ✔
</dtl:if>
Currently, DTL doesn't support using inline if statements.
Switch statements are used to include one of two or more blocks of elements based on a case choice. Switch statements are represented by dropdowns of possible case values in the GUI.
Swtich statement syntax:
<dtl:switch={switchName}>
<dtl:case={optionOne}>
This block of text will only be included in the generated copy of the document
if optionOne is selected as switchName
</dtl:case>
<dtl:case={optionTwo}>
This block of text will only be included in the generated copy of the document
if optionTwo is selected as switchName
</dtl:case>
<dtl:case={optionThree}>
This block of text will only be included in the generated copy of the document
if optionThree is selected as switchName
</dtl:case>
</dtl:switch>
Currently, DTL doesn't support using inline switch statements.
You need at least one empty line or a line of regulat text (that doesn't use DTL) at the end of your document. This issue is caused by an Apps Script limitation.
This project is licensed under the MIT License. For further information, please check the LICENSE file.