Well, sort of. The thing is, finding a templating engine is pretty easy. There are plenty of them. And many of them work the same way. I’m not sure I’m in a place where I could say I have a “favorite.”
Instead, it’s more about finding one that achieves what we need. So what works for one project may work for another project or it may not.
For this project, we’ve opted to use tplite.
From the project’s homepage:
Sound simple enough, doesn’t it? Here’s the thing, though:
- it’s a really small engine,
- it supports variables, expressions,
- it has support for conditionals and loops,
- and the documentation is solid on how to use it.
And if you’re using NPM to manage your packages, including it is as easy as it gets:
To Get Started
If this particular engine seems interesting to you and you have NPM installed, here’s what you need to do to get started:
- Create package.json and include the above code.
- Run npm install or npm update if you’re already using it.
- Include the code using wp_enqueue_script.
Here’s the thing, though: The script will be located in a node_modules directory so your code may look something like this:
But if you opt not to distribute that particular directory with your final project, you can move the file to an assets directory or whatever it is you opt to do to make it as easy as possible to include in your work.
Regardless, once it’s registered and enqueued, you can use it like in the example earlier in the post.
A Word About Licensing
For what it’s worth if you’re working in WordPress and you’re concerned about whether or not it will be compatible with its license, tplite is under MIT so, yes, it’s a compatible license.