Output code within the page body

Under Settings -> Analytics & Custom Code in the administration, you can set some custom code to output after the opening <body> tag.

A common use could be some tracking code to show on all pages. Or, you may need to set a portion of the Google Tag Manager code.

In order to use that code in your templates, you must set the following tag somewhere in your templates.

 
{{ _page.bodyStartCode() }}

Set the opening <body> tag code in your templates.

You can also add code to be output after the opening <body> tag in your templates. This code will only be output with the {{ _page.bodyStartCode() }} tag.

There are two methods to add the code. 

If your code is short or saved to a variable then you can do the following.

{% do _page.addBodyStartCode('MY_CODE_HERE') %}

If your code is multiple lines then you can do the following.\

 
{% bodyStartCode %}
<script>
  const var = 'Some longer code here';
</script>
{% endBodyStartCode %}

Output code before the closing </body> tag

Under Settings -> Analytics & Custom Code in the administration, you can set some custom code to output before the closing </body> tag. 

An example use case would be if you need to set the Javascript code to use a chat tool.

In order to use that code in your templates, you must set the following tag somewhere in your templates.

{{ _page.bodyEndCode() }}

Set the closing </body> tag code in your templates.

You can also add code to be output before the closing </body> tag in your templates. This code will only be output with the {{ _page.bodyEndCode() }} tag.

There are two methods to add the code. 

If your code is short or saved to a variable then you can do the following.

 
{% do _page.addBodyEndCode('<script>Some code here</script>') %}

If your code is multiple lines then you can do the following.\

 
{% bodyEndCode %}
<script>
  const var = 'Some longer code here';
</script>
{% endBodyEndCode %}
This documentation is only for Aptuitiv CMS. Learn more.
Get Started With Aptuitiv