learn | unlearn | relearn

Beginners seem to be facing issues to change the built-in Web 2 Bootstrap template of Xojo Web 2. If someone is not used to it, it is indeed difficult to learn CSS in parallel to absorb all the new functionality of Web 2.

Understanding the basics


There are many possible workflows to get the job done, and many can be achieved, without touching any third-party tool but using the developer tools of your browsers.

The purpose of his tutorial is to explain the backgrounds to a beginner. Please bear with me, that consequently it might be unprecise for seasoned developers. The more experienced user should anyway start reading the chapter “A deeper dive into customization of your template!

HTML

As you are reading this, I assume that you have at least a minimal understanding of HTML. If not you should have a look at w3schools.com.

This is a simple sample of an HTML page:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

</body>
</html>

Styles

With styles you can change the look & feel of your code:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>

</body>
</html>

CSS

A CSS file is an own file containing nothing but all “styles”. You can use them in your HTML code by referring to them through classes or “overwriting” the style of an element. The following code is showing how the code in the paragraph above will look like in a CSS scenario:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>

and the mentioned CSS file ‘styles.css’ will look like this:

body {
  background-color: powderblue;
}
h1 {
  color: blue;
}
p {
  color: red;
}
view raw

What has this all to do with Xojo Web 2.0?

What is bootstrap all about?

Xojo Web 2 is based on a web framework. The used framework is called Bootstrap. If you are interested in learning more about web frameworks, Wikipedia is a good starting point:

Web framework - Wikipedia

There are many frameworks out in the wild. Many are passing away over time, others are known to be relatively or very stable. Bootstrap belongs to the latter category and this is the reason why Xojo Web 2 is using this particular framework. Love it or hate it, but there are little chances it will change any time soon.

Bootstrap has its own CSS file, where all the default colors, margins, etc. are defined. The file is called: bootstrap.min.css. The word “min” stands for “Minification”. That’s important to understand, as a minified CSS file is utmost impossible to edit but the final version should be minified to reduce the load for the browsers to a maximum. The fact that this file is minified might be a big stumbling block for beginners as it looks weird. No worries, we will tackle this later.

A lot of theory, show me more insights!

On my Github repository “Xojo Web 2 Bootstrap Boilerplate” you will find a binary file in the “Xojo Examples”-folder (so it can be used by every Xojo user) called:

Xojo_Web_2_Boilerplate.xojo_binary_project

This program has no functionality other than showing a handful of buttons in all kinds of colors.

View in the Xojo IDE
Browser View

Let’s debug the progam. The IDE will create a build folder (usually in the location of your binary file). This is the next part where some might be struggling, you don’t find any trace of a css file in these folders:

The reason is simple, Xojo is managing (and providing) the bootstrap CSS file internally, so you will NOT see it in your resources. But let’s look deeper at the browser running our app in debug mode. I’m using Chrome in this example (Depending on the browser you are using, you might have to switch on the Developer functionality).

Look at the source code of your web app whilst running in your browser

Look at line 18, there it is! We found the bootstrap.min.css.

Line 18 is showing the bootstrap.min.css

Now manipulating this file would not make any sense as it is “volatile” and will change with every compilation. This explanation is only for you to better understand the logic. The Xojo App is feeding the browser with a bootstrap CSS file, and this file is responsible to define many aspects of your app.

How can we change the built-in Bootstrap Template of Xojo Web 2?

The good news

The Xojo development team made it very simple to add you own bootstrap.min.css (Note: it has to be named exactly(!) like this).

Just drag and drop your own bootstrap.min.css file into the IDE and you are done. I created on my Github repository “Xojo Web 2 Bootstrap Boilerplate” a folder Xojo New Bootstrap Template.

Please move the bootstrap.min.css file from within that(!) folder into your IDE, where of course our dummy project has to be open.

As you can note the design in the IDE did change, and an item called “bootstrapmin” is showing up in your outline. For the time being there is no special functionality behind this item, it is only an indicator that you have inserted an own minified Bootstrap CSS file. You can double-click on the file, but as it is minified, you will have no fun editing any larger changes.

Bootstrapmin is showing up after we added our CSS file

After running the App again in the IDE, we can notice that the layout changed (different and smaller buttons).

Our bootstrap design was applied to our app

The Bootstrap sample applied in the above example is SIMPLEX, which you can download here.

A quick look under the hood

If you look into the debugger file now, you will see a change there as well:

After customization, we can see “our” CSS file in the resource folder

This is not too important to memorize and not useful (you should never change this bootstrap CSS file, as it will get overwritten via your next compilation) but it is an indicator for you that your project is using a customized bootstrap.min.css.

The less good news

As you have seen the buttons in our example are a bit smaller. If you are making big changes in your CSS Layout this will consequently mean, that you have to reflect these changes in your UI design as well. You might prefer the look of smaller buttons, but it can very well be that your caption-text will not fit any longer.

The same applies to changes in font types, margins, etc. Some people dislike this, but it’s just the nature of the beast and was no different from the style manager of Xojo Web 1. If you will make significant changes in your own Bootstrap CSS file, you will most likely have to reflect all those changes in your UI. Keep that in mind! This is just what web design is all about it. It is no different for WordPress or any other web application which is using Bootstrap. It works fine out-of-the-box, but if you are making customizations, you have to live with the consequences (and/or handle them).


In our next chapters, I will show you my workflow to adapt the standard template of Xojo Web 2.0. Before you continue to read you must be familiar with the concepts explained above.For a beginner, it is probably a good moment to play around with a few examples and to see the changes in the IDE and the final app.
For reasons of simplicity (and very likely laziness) I used only buttons in my example. Add other components from the Xojo library, add a new bootstrap theme and look at how things will change in-between. It is always important to get a “feeling” about what is going on. No one can teach you that experience, you will learn it best by trying it on your own. Don’t be frustrated if it doesn’t look quite nice, that’s not the purpose of this exercise.
You can download pre-made designs at bootswatch.com and many other places on the internet. Search engines are your friend. But be prudent! Many people are facing challenges with bootstrap — You will find a plethora of pages offering fake templates, or fake apps promising you an easy layout of templates, etc. Please think twice if a site is safe or a hoax.

A deeper dive into the customization of your template!

At the very beginning, I showed a HTML file calling (or better embedding) as CSS file. I showed above that this is exactly how Xojo Web 2 is working as well. The Xojo app is drawing the overall “architecture” of the app, which means the controls and where they are located but it is mainly the CSS file, which is defining the real look and feel.

Now how can you change and — more importantly — preview the changes you are making in a CSS file?

You can only preview the HTML code of a file without CSS but the CSS file alone will be previewed as pure text in any browser. And HTML without CSS doesn’t look good: It is important to understand that both files are working together. The whole concept of cascading style sheets is about separating the content and structure (HTML) from the design (CSS). But you need to have an HTML document that embeds your CSS file to preview any changes you make in CSS. Let’s first look at the following screenshots:

1. Browser-view of the HTML file w/o the css file:

HTML View of Buttons (extract)

2. The minified CSS file opened in a browser:

Minified CSS View related to buttons (extract)

3. the HTML / CSS combo viewed in a Browser:

The actual view in the Browser of the HTML file embedding the CSS file

Two things are important to note for §3:

  • It only works fine in a server environment (more on this later), but the above template needs to run javascript, etc.
  • The HTML needs to have a line embedding the CSS, e.g. 
    <link rel=”stylesheet” href=”../bootstrap.min.css”>

The “../” sequence means that the bootstrap.min.css file is located in the same folder than the html file.

Learnings:* We need some HTML document to show the CSS elements we want to change (otherwise we can’t preview them).
* We need to embed our CSS file into this HTML file.
* We best need a little server environment to mimic the future server architecture.
This said: we should best work with some tools to get all this achieved and not reinvent the wheel.

Let’s talk about tools

There are tons of tools out there in the wild. Either online or for Windows, macOS, Linux, or all three. Even most modern browsers can show (and edit) the embedded CSS(es) of a webpage.

I have chosen Brackets[] for this tutorial for the following reasons:

  • It’s easy to install
  • It’s robust
  • It’s available for many platforms
  • It’s free of charge (open-source)

And most importantly it has a great “live” pre-view mode, which means you can see most changes you make in your files instantly in your browser or after a quick refresh. As such it can run as well all kinds of embedded scripts.

Once installed it is as simple to open the folder where your index.html and CSS are located (hang on a second, I’ll explain this in a minute).

Use this symbol in the Brackets to launch the embedded “server” and to preview your work

Prerequisites

1. CSS File

I believe this one is confusing many people. How can I get the bootstrap.min.css Xojo is using as default if it is not provided by the IDE and not visible in the compiled file? If you are lazy, just look at my Github repository “Xojo Web 2 Bootstrap Boilerplate”, it is included there.

Alternatively, open your compiled or debugged app in a web browser of your choice and via the development tools find the bootstrap.min.css. You can usually download it by a simple right-click on that file.

View in Safari

Therefore you have to activate the development features in Safari under Preferences “Show Develop menu in menu bar”:

After activation, you can use “Show Page Resources” while your Xojo Web App is running.

I believe it is important to use exactly the version Xojo is using, mainly because you never know if they might change it or not. Newer versions of bootstrap might not be compatible in the future, though it currently seems they are.

The Bootstrap version used in Xojo Version 2020 Release 1.2 is Bootstrap v4.4.1. For your convenience, the Github repository “Xojo Web 2 Bootstrap Boilerplate” contains a folder “Original_Bootstraps” with the original Bootstraps per Xojo version.

If you look at the bootstrap.min.css file from the Simplex Theme, the used Bootstrap version is different: 4.5.3.

Tip: always comment on all changes you will make in your CSS-File! If Xojo will in the future change the used Bootstrap default file, it will be much easier to update that new version accordingly.

Please note that our CSS file is minified. Let’s first rename it from

bootstrap.min.css to bootstrap.css, which means skipping the “min”. This is a prerequisite for the next steps in our workflow.

Renaming doesn’t of course change anything that the file is still minified, but the conversion described in the next paragraphs will not work properly if you don’t rename this file first! So we now have to files, named differently but they are both still minified.

Open the app “Brackets” and chose open folder to read the root folder of the Github repository “Xojo Web 2 Bootstrap Boilerplate”.

Chose open folder to open our project

You will now see the following screen:

We can’t work with this minified version. Therefore let’s install some plugins. Brackets has its own Extension Manager. Please ensure that the following extensions are installed:

  • Beautify (this one is used to de-minify a file)
  • JS CSS Minifier (this one is minifying files)

BEAUTIFYING our CSS:

In our project mark the file bootstrap.css and click on the following icon on the right-hand side of the app:

This icon will “beautify” (de-minify) your code

Or use a right-click in the editor window:

Brackets will now do all the magic and de-minify (beautify) your file:

Now we have finally a format that is human readable and easier to edit!

MINIFYING our CSS:

Vice-Versa you can use “minify” by right-clicking on the editor to create a new bootstrap.min.css file:

You can see in the outline, that a bootstrap.min.css file was created:

Remember that in your final product you should always use the minified version only!

2. HTML File

We learned above that we can only see the changes we will make in our bootstrap file if the CSS file is embedded into a HTML file. But these HTML files need to use the objects from the CSS file. We can either build a Xojo App with all needed controls and then use the built-in CSS functionality of the browser or (and that’s what we’ll see right now) we have to work with workaround.

Our workaround consists of building all controls into the HTML document which embeds our bootstrap.min.css.

For that purpose you will find the index file in the Github repository “Xojo Web 2 Bootstrap Boilerplate”:

  • index.html (showing all Bootstrap elements)

Finally, we can customize our own bootstrap file

Before we are starting this work, please keep in mind that you must minify your results and you must ensure that the file is called “bootstrap.min.css” before you will drag&drop it into the Xojo IDE.

Please open our project in the preview mode of Brackets[]. We clicked in the internet browser the red button called “danger”. As you can see Brackets[] is immediately jumping to the code line responsible for drawing this button in HTML.

We can see that there is a class “btn” used by all buttons and a class “btn-danger” used only for the “danger”-button.

Let’s search our CSS file for “btn-danger” now:

We can see that the class “btn-danger” (marked with a “dot”) has a color property for the text. Let’s change this to “000” (black) and see if there is a change in the preview window:

Nothing has yet changed! Why?

What happened? Remember that we have the “minified” version of our CSS file embedded into the HTML document we are editing. But in our example, we are editing the “beautified” version of the CSS file! This means that we have to first create out minified version, as we had learned above:

Don’t forget to minify your CSS file, only after his the changes will appear in the preview!

And now we can see the changes. The text-color of our button “danger” has changed to “black”.

Let’s now move our ”bootstrap.min.css” file into our Xojo Project from the very beginning (remember you can find it in the Github repository “Xojo Web 2 Bootstrap Boilerplate” under “Xojo Examples”).

Preview in the Xojo IDE
Bang! Our new bootstrap.min.css is working in our compiled Xojo App!

It doesn’t work for me!

I bet that you have used the wrong “bootstrap.min.css” file. As the file has to be named exactly in this way it is unfortunately very likely to mess up with files.

Especially as it is possible to drag&drop a normal CSS file into the IDE. You know that you have moved a valid bootstrap file if you the little Bootstrap icon:

Pay attention to which bootstrap file you will copy into the IDE!

“jeannots_special_css.css” is a duplicate of the “bootstrap.min.css” but it won’t work! You know that you did everything right if you will see the “Bootstrap-Icon” and if the name of your file magically changed to “bootstrapmin”.

What are the next steps?

The magic of Brackets[] is that it comes with a built-in “auto-complete”-functionality.

Showing all CSS options for “padding”
Showing all CSS options for “text”

It is now up to you to design/adapt the bootstrap template as you see fit. It is pretty much similar to the changes you made in the Web 1 stylizer, but this template can not replace that you have to dig deeper into Cascading Style Sheets and how to customize them in the best possible way.

But it is important to keep one last thing in mind. All the changes you make in the Bootstrap Template are applied “globally” to the respective objects in your app.

This means that if you change one button in our HTML workaround HTML-file, your generated “bootstrap.min.css” will logically apply to all those buttons in your Xojo Web App 2. If you want to change only one button you have to use the built-in “style-option” in Xojo Code or inject “<raw>”-code into this Xojo-object. You can find a few examples in the Xojo Forum. But not every object can be changed this way nor will available CSS and HTML attributes (yet) work.

Updates:

2020/11/24 17:36
Added the Xojo Version 2020 Release 2 bootstrap.min.css to GitHub (for completeness, it doesn’t seem to have changed though).

2020/12/02 15:43
The following article show how to adapt object individually:

How To Customize Xojo Web 2 Objects
Following up on my article “How To Customize Xojo Web 2 Bootstrap Template” I want to quickly show how you can customize Xojo Web 2…

Comments

Sign in or become a jeannot-muller.com member to join the conversation.
Just enter your email below to get a log in link.



You’ve successfully subscribed to jeannot-muller.com
Welcome back! You’ve successfully signed in.
Great! You’ve successfully signed up.
Your link has expired
Success! Check your email for magic link to sign-in.