Conditional content allows you to customize your Google Docs template and generate different versions of the same document based on the user’s answers. In this tutorial, I’ll show you how to use conditional content in Google Docs using Document Studio, a Google add-on that automates document creation.
If you are new here, please follow this step-by-step guide on how to generate documents from data in Google Sheets and Google Forms responses.
Let’s say you are a recruiter who wants to use a Google Docs template to send out job offer letters to candidates. You want to include specific information in the offer letter based on the candidate’s job title and location.
The conditional statements that we would like to include in the document template are:
Create a new Google Docs document and create a job offer letter template. Include sections for the candidate’s name, job title, location, salary, and benefits package.
Use the <<if>> and <<endif>> expressions to define the conditional sections in your template. For example, you might use the following expressions to show or hide the relocation package section based on the candidate’s location:
<<If: ({{Location}} != 'San Francisco')>>We are pleased to offer you a relocation package to assist with your move from {{Location}} to our main office.<<EndIf>>Similarly, you can wrap the benefits paragraph with the <<if>> and <<endif>> expressions to show or hide the benefits package section based on the candidate’s job title:
<<If: OR (({{Job Title}} == 'Manager'), ({{Job Title}} == 'Director'))>>As {{Job Title}}, you will be eligible for our comprehensive benefits package, which includes health, dental, and vision insurance, a 401(k) retirement plan, and more.<<EndIf>>You may also use the
~contains operator in place of==equals operator for partial matches. For instance,{{Job Title}} ~ 'Manager'will matchSales Manager,Senior Manager,Managerand so on.
Here’s how the final job offer letter template looks like.
https://www.youtube.com/watch?v=UbMlmckpZDg
In addition to document templates, you can also add conditional text in email templates with the help of scriptlets.
Things to know:
OR, AND or NOR operator to combine multiple conditions.<<if>> and <<endif>> tags outside the table.