Worklog Part 1: Building web application with Bootstrap


Integrating Start Bootstrap template

{% comment %}

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:

H:\Ampps\www\worklog\web>bower install startbootstrap-sb-admin-2

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.


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):


All resources should be loaded successfully .

The content of twig base file:

{# Base page template #}

    <!-- FAVICON -->
    <link rel="icon" type="image/x-icon" href="{{app.request.basepath}}/favicon.ico" />
    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="{{app.request.basepath}}/bower\_components/bootstrap/dist/css/bootstrap.min.css" />

    <!-- MetisMenu CSS -->
    <link href="{{app.request.basepath}}/bower\_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">

    <!-- Timeline CSS -->
    <link href="{{app.request.basepath}}/bower\_components/startbootstrap-sb-admin-2/dist/css/timeline.css" rel="stylesheet">

    <!-- SB-Admin CSS -->
    <link href="{{app.request.basepath}}/bower\_components/startbootstrap-sb-admin-2/dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="{{app.request.basepath}}/bower\_components/morrisjs/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="{{app.request.basepath}}/bower\_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- Worklog custom CSS -->
    <link rel="stylesheet" href="{{app.request.basepath}}/css/worklog.css" />
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--\[if lt IE 9\]>
      <script src=""></script>
      <script src=""></script>
{% endblock %}    
<!-- Bootstrap Core JavaScript -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="{{app.request.basepath}}/bower\_components/bootstrap/dist/js/bootstrap.min.js"></script>    

<!-- Metis Menu Plugin JavaScript -->
<script src="{{app.request.basepath}}/bower\_components/metisMenu/dist/metisMenu.min.js"></script>

<!-- Morris Charts JavaScript -->
<script src="{{app.request.basepath}}/bower\_components/raphael/raphael-min.js"></script>
<script src="{{app.request.basepath}}/bower\_components/morrisjs/morris.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="{{app.request.basepath}}/bower\_components/startbootstrap-sb-admin-2/dist/js/sb-admin-2.js"></script>

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


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. {% endcomment %}