How to Add Asyntai AI Chatbot to CrafterCMS
Step-by-step guide for CrafterCMS websites
Step 1: Get Your Embed Code
First, go to your Asyntai Dashboard and scroll down to the "Embed Code" section. Copy your unique embed code which will look like this:
<script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script>
Note: The code above is just an example. You must copy your own unique embed code from your Dashboard as it contains your personal widget ID.
Step 2: Add to FreeMarker Template (Recommended)
CrafterCMS uses FreeMarker (.ftl) templates for rendering pages. The easiest way to add the chatbot to all pages is by editing your main page template:
- In Crafter Studio, go to Site Dashboard > Content Types or navigate to templates
- Open your main page template (e.g.,
/templates/web/pages/home.ftlor the base layout) - Find the closing
</body>tag - Paste your Asyntai embed code just before the
</body>tag:<!-- Asyntai AI Chatbot --> <script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script> </body> - Save the file and publish through Crafter Studio
Tip: Adding the script before the closing </body> tag ensures it loads after the page content, which is recommended for chat widgets and won't slow down your page loading.
Alternative Method 1: Using Crafter Template Components
For better organization, create a dedicated component template for the chatbot widget:
- In Crafter Studio, create a new template file at
/templates/web/components/asyntai-widget.ftl - Add the following content to the component template:
<!-- Asyntai AI Chatbot Component --> <script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script> - Include it in your main layout template using a FreeMarker include directive:
<#include "/templates/web/components/asyntai-widget.ftl" /> - Alternatively, if using Crafter's component rendering system, use:
<@renderComponent component=contentModel.asyntaiWidget /> - Save both files and publish through Crafter Studio
Note: Using a separate component template makes it easy to enable or disable the chatbot across your entire site by commenting out a single include line.
Alternative Method 2: Using Crafter's Head/Scripts Configuration
CrafterCMS allows you to inject scripts globally through site configuration:
- In Crafter Studio, navigate to Site Config > Configuration
- Open the Engine Site Configuration file (
site-config.xml) - Add a custom script injection configuration:
<site> <!-- Existing configuration... --> <!-- Custom Scripts --> <scripts> <script> <src>https://asyntai.com/static/js/chat-widget.js</src> <async>true</async> <data-asyntai-id>YOUR_WIDGET_ID</data-asyntai-id> </script> </scripts> </site> - Alternatively, edit your base FreeMarker layout to read from site configuration and inject scripts dynamically:
<#if siteConfig.getString("scripts.script.src", "")?has_content> <script async src="${siteConfig.getString("scripts.script.src")}" data-asyntai-id="${siteConfig.getString("scripts.script.data-asyntai-id")}"></script> </#if> - Save and publish the configuration changes
Tip: Using site configuration allows you to manage the chatbot widget without modifying template files directly, making it easier to update or remove later.
Alternative Method 3: Using Groovy Controller
CrafterCMS supports Groovy scripts for server-side logic. You can use a controller to dynamically add the chatbot script:
- Create a Groovy script in
/scripts/pages/(e.g.,/scripts/pages/home.groovyor your site-wide controller) - Add the following code to inject the script URL into the template model:
// /scripts/pages/home.groovy import org.craftercms.engine.service.context.SiteContext def siteContext = SiteContext.current // Add Asyntai chatbot configuration to the model model.asyntaiEnabled = true model.asyntaiWidgetId = "YOUR_WIDGET_ID" model.asyntaiScriptSrc = "https://asyntai.com/static/js/chat-widget.js" - Then reference the model variables in your FreeMarker template:
<#if model.asyntaiEnabled?? && model.asyntaiEnabled> <script async src="${model.asyntaiScriptSrc}" data-asyntai-id="${model.asyntaiWidgetId}"></script> </#if> - Save both the Groovy script and the template file
- Publish the changes through Crafter Studio
Note: The Groovy controller approach is useful when you need conditional logic (e.g., enabling the chatbot only for certain user roles or page types) or when you want to pull configuration values from external sources.
Step 3: Publish and Verify
After making your changes, publish them through Crafter Studio:
- In Crafter Studio, go to Site Dashboard
- Review your changes in the My Recent Activity or Pending Approval section
- Click Publish to deploy the changes to your live site
- Visit your CrafterCMS website in a new browser tab or incognito window
- You should see the chat widget button in the bottom right corner
- Click it to make sure it opens and works correctly
Not seeing the widget? Make sure you published the changes through Crafter Studio. Verify that you're editing the correct template file that your pages use. Clear your browser cache or view in an incognito window. If using Crafter's caching, clear the Engine cache from the Crafter Studio dashboard.
Template Location: CrafterCMS template locations may vary depending on your project structure. Common locations include /templates/web/pages/ for page templates, /templates/web/components/ for component templates, and /templates/web/ for layout templates. Check your existing templates to find where the </body> tag is defined.
Weebly