Hi All,
Apologies for what seems like a pretty basic question. I’m developing a custom theme and I’m looking to make use of some external libraries to add functionality to my theme.
I have taken the start theme and successfully added that to a local instance of ghost.
In this case I added the typewriter-effect
library (see: GitHub - tameemsafi/typewriterjs: A simple yet powerful native javascript plugin for a cool typewriter effect.).
I ran yarn add typewriter-effect
and it installed the library and added it as a project dependency. I then thought all I needed to do was start using it. I added a script block to the bottom of a custom page and placed in my typewriter sample animated text instructions. Refreshing the page the console said Reference Error: Typewriter variable not found
.
I tried adding the CDN reference to the bottom of the default.hbs
area above </body>
but that made no difference. I finally added the CDN reference above the other script at the bottom of my custom page and it is currently working.
So my questions are:
-
If I have installed the package as part of the project why do I need to provide a reference via CDN? I can see I could use CDN instead of the installed package, but shouldn’t it work with the installed package too?
-
What is the “best practice” for adding in javascript like my typewriter code? Should I include it as a script in assets and then import instead of putting it in inline in the page template?
Many thanks,
Dave