Worklog Part 2: Creating navigation with bootstrap

Creating navigation with bootstrap

We were start from already prepared bootstrap theme sample and we will try to take as much as possible out of it.


Navigation bar will be at the top of each application page and should be always visible. All shared elements which are on all pages,  are going to the base layout, this is base.html.twig in our application.

If you need some specific information about bootstrap you can probably found it on this site. site is one of my primary sources for web and SQL related questions.

After some experimentation I create something like that:

2015-12-06 12_18_10-Dashboard - Bisaga Worklog

Main navigation bar at the top is always visible even when we scroll down beyond visible space (navbar-fixed-top). This require little additional CSS settings that our pages on the top has some default margin.


In our worklog.css we define default top margin as:

Because we define “body” element as selector, this will be valid for every web page in our web site.

Navigation tag with bootstrap  settings

One part of template looks like:

We create navigation bar with brand icon on the left and some icons with two direct links (calendar, alerts) and two drop-down menus for some additional actions.

You can download the whole file from here.


Default page on the web site will be used as dashboard, so we create dashboard.html.twig template file and controller class in  DashboardController.php . We also connect default ‘/’ route to this controller (Application.php).


For links we use direct path navigation with little help of Silex Application constants, so links are assembled like this:

In some point I will probably study assetic component from Symfony but for now I will stick to this simplest semi-direct references.


Icons are actually characters from the font Font-Awesome. Images on the navigation bar are slightly larger (fa-lg) then those in drop-down menus.

You can learn more about font awesome usage here.

This sample application is published on github.

Worklog Part 1: Building web application with Bootstrap

Integrating Start Bootstrap template

We will implement bootstrap based web application theme in Silex application. The best way to start out is with already available theme.

To install it into our application just execute bower install command in application web folder:

After installation of all required components (including jquery, bootstrap  and a few others) we will need some help how to use them. You can download sample implementation and start learn directly from included sample application.

After unzipping sample into local www folder we can navigate to it and start inspecting how it is constructed.

2015-11-26 19_08_40-SB Admin 2 - Bootstrap Admin Theme

This beautiful sample contain almost everything what is needed to build very powerful web application !

Next step is converting part of this sample code into our application.

Integrating template in silex application

We need to analyze index.html file from the sample and transfer definitions into our base.html.twig file.  As you can see in the content of twig file, we only copy “link” and “script” nodes to our file and adjust locations of used resources.

After you have everything in place the response after loading index.php should be something like this (Firefox/Developer tools/Network screen):

2015-11-26 19_46_09-Network - http___localhost_worklog_web_index.php

All resources should be loaded successfully .

The content of twig base file:

Worklog application folder now grow little larger because of new front-end components in bower_components folder.

2015-11-26 20_03_12-Programmer's Notepad - [index.html]

At this point our web application is almost empty, but we have all  necessary components ready to use.

This example application is available on the Github.