Jump to content

Javascript being removed in header.tpl


Recommended Posts

I'm trying to place javascript just after the opening <body> tag in header.tpl. I am using {literal}{/literal} to surround the code. If I put anything, even a comment, inside the <script> tags they disappear when viewing source. PS v1.6.0.6.

Example of what I am using and this doesn't even work:

{literal}
<script type="text/javascript">
// just a comment
</script>
{/literal}

When I view source, I see nothing where the code should be. It's almost like there is a scrubbing function that removes any JS if in header.tpl. I've placed JS in footer.tpl and have no problems.

 

??? Thoughts ???

Link to comment
Share on other sites

You can get some scripts to stay in the header with a few steps. The first is to perform an Media class override. https://gist.github.com/hereswhatidid/8c8edef106ee95138b03. Then you need to set a variable in the FrontOfficeController to send to the smarty template. In the header.tpl, an {if isset} wrapped around your script will place it into the header. Not a great solution, but works when you need to add Google Tag Manager data layers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...