Auto-Include Bootstrap4 If Not Already Included
In this example, we'll assume your template needs Bootstrap4 as the preferred CSS framework. Note that this works for other frameworks as well, with minor modifications. But if it's used on any page, you may have one of the following situations:
- Bootstrap4 could already be included - so you shouldn't do anything
- A different CSS framework is included - so you should include Bootstrap4 automatically
- The current CSS framework can't be detected, so to be safe, you should include Bootstrap 4 as well, until the theme is updated to broadcast what it's using
This page shows how to handle these problems with almost no code. Note that we've place the code in a separate file and use a helper to achieve this, as this allows us to re-use the code in multiple templates.
BTW: to see that this works, try switching the theme of this page to one without a koi.json
or one with a different css-framework.