Skip to main content
Home  ›  Blog

New Content-Templates for Bootstrap 3, 4 and others - using Connect.Koi

The new default content templates now support Bootstrap 3 and 4 at the same time, thanks to Koi.

The Result

Now when a user of 2sxc 9.22 (which includes Koi 1.03) or higher, the installation dialog will look like this: 

When these are installed, the content will automatically look right - for example in DNN Contra (Bootstrap 4):

...or with this demo Bootstrap 3 theme:

Here even an example using the old standard DNN Gravity-theme:

The great thing about it is that it works perfectly with just about any CSS Framework - or even if no CSS Framework in installed. Here's how it works:

4 Scenarios Supported

The following scenarios are covered, and handled differently:

Bootstrap 3 With koi.json

If the theme/skin has Bootstrap 3 and includes a Koi.json in the theme-folder publishing the information, this happens:

  1. Bootstrap 3 is auto-detected
  2. no additional Bootstrap 3 is loaded from any CDN
  3. the bs3.css is loaded with the necessary styles
  4. all class attributes contain thecorrect Bootstrap 3 styles

...and everything works!

Bootstrap 4 with koi.json

This behaves exactly like Bootstrap 3, so all the correct parts are included (bs4.css) and the full Bootstrap isn't loaded from the CDN, and everything works. 

All Scenarios without koi.json

In case a theme doesn't communicate the framework - which is often the case on existing themes - it will behave as follows:

  1. situation "unknown" is auto-detected
  2. Bootstrap 4 is automatically loaded from a CDN
  3. the remaining behavior is treated as if it were Bootstrap4

...and everything works! Logged-in admin users are also informed that this happened, and are urged to add a koi.json to the theme-file, because it would then not need to load Bootstrap 4 from a CDN. 

Other CSS Frameworks with koi.json

If other css-frameworks are used - like Foundation 6 - the situation "other" is auto-detected, and the behaviour is the same as a missing koi.json, just without the admin-warning. 

How It's Done - Best Practices

Based on our development experience, we believe this is the best way to do it, and recommend a similar setup for your Multi-CSS implementations. Here are the code-snippets you'll find in the Razor templates, which have these effects:

Include bs3.css or bs4.css (fallback is also bs4.css)

<!-- from -->

<link rel="stylesheet" 
  href="@App.Path/dist/@(Koi.PickCss("bs3,bs4", "bs4")).css" 
  data-enableoptimizations="true" />

Provide different class-attribute, based on framework

  line breaks added for readibility

<div @Koi.Class("
    bs3='col col-xs-12 col-sm-6 col-md-4 sync-height-with-neighbors' 
    bs4,oth='col-12 col-md-6 col-lg-4'")

Include Bootstrap 4 from CDN if not Bootstrap3/4

// from

  <link rel='stylesheet' href='' 
    crossorigin='anonymous' data-enableoptimizations="true" >
  <script src='' 
    crossorigin='anonymous' data-enableoptimizations="true" ></script>

So Why Bother?

You may ask yourself, why bother. We could just provide two different sets of templates, or we could just switch to Bootstrap 4 all the way. Here's why:

  1. If a site has different pages using different themes, this will still work
  2. If a site start with Bootstrap 3 today, and upgrades the theme to Bootstrap 4 tomorrow, it will magically just continue to work
  3. If a site tries out a Bootstrap 3 theme, and decides to ditch it for something else, everything still works
  4. Whatever we install today, should be future-proof, and this makes it possible
  5. If we support more frameworks later, the entire setup already works

So basically the goal is: to matter what people are doing, this should just continue to work - like magic. And in the long run, maintaining one set of templates is more efficient than multiple sets. 

Install or get the Code from Github

To install it, it will always be the recommended install on 2sxc 9.22. If you want to discover the code, check out the new github repo 2sxc-content-app.

We Love it - Hope You Love It Too!

With love from Switzerland,
Daniel, Tom and Luca

Daniel Mettler grew up in the jungles of Indonesia and is founder and CEO of 2sic internet solutions in Switzerland and Liechtenstein, an 20-head web specialist with over 800 DNN projects since 1999. He is also chief architect of 2sxc (see github), an open source module for creating attractive content and DNN Apps.

Read more posts by Daniel Mettler