Hello Everyone,
I got bored reading PHP questions. So, this is probably the best time to add another article here at daniweb.com. If someone ever stumbled upon by boring blog (mini-tutorial), I talked about how light and simple is the tinybutstrong templating engine. However, I began to wonder why not too many people are using it.
Months ago, I went to their site and read their implementation and I finally answer my own question. The reason most people would ignore the validity or the existence of tinybutstrong is that, until now they are using the tables instead of div on their example of implementation. So, I guess it is safe to say that developers and designers these days does not have anything to do with tables, UNLESS, it is deem necessary :).
Why is TinyButStrong, a good template engine?
I am confident it has potentials. However, it is and can be powerful as any BIG template engines available out there .. can be considered somewhere just below twig and smarty. What makes it good is that it has one 1 Php class with 6 methods and 5 properties. This one file makes it a templating engines runner up :).
How do we use TinyButStrong?
Please read tutorials below..
First Step: Download the tinyButStrong here. Unzipped this file and move the tbs_class.php to your working directory.
Second Step: In your working directory (server of course), create a new dirctory called 'templates'.
Thirs Step: Copy and paste codes below to your notepad, or any suitable program editor. Save as index.php
filename: index.php
<?php
include_once('tbs_class.php');
## Written by veedeoo from daniweb.com and tutpages.com 2012.
## reposting of this script is not allowed except, on those two domains mentioned above
$title = "This site is powered by TinyButStrong";
$metaDesc = "this is the coolest site on the net";
$metaKeywords = "cool,site,internet,number one,ever,created with TinyButStrong";
$mainContent = "Lorem ipsum dolor sit amet, tritani dissentiunt ne est, an commune maluisset consequat sed. Cu sit odio voluptua, quidam evertitur nam no. Usu ne assum feugait scriptorem. Qui luptatum instructior in. Alterum interpretaris at pro, nibh etiam mucius an est. Sed fugit augue constituam ne .";
## IMPORTANT contents above can be from database.
$rightContent = "This is the right column content";
$footerContent = "This is footer content";
$Vedeoo = new clsTinyButStrong (array('chr_open'=>'{{', 'chr_close'=>'}}') );
$Vedeoo->LoadTemplate('templates/index.tpl');
$Vedeoo->Show();
Brief Explanations of the codes above..
First, this line of codes
$Vedeoo = new clsTinyButStrong (array('chr_open'=>'{{', 'chr_close'=>'}}') );
That is an instance of the tinyButsrong class, and I telling the template engine that I want my delimeter change to
{{ and }}.
Why change the default delimeter? Well, the response is simple.. I want it to be like the smarty delimeters so that I can easily modify it to become functional in smarty templating environment.. In fact we can change the delimeter to Twig like delimeter e.g
{% and %}
.. but that is not within the scope of this tutorial. I have plans to write one in the near future.
Lets move on to the next codes that requires our attention. This codes right here
$Vedeoo->LoadTemplate('templates/index.tpl');
That tells the template parser of the directory of the template file. In this example I have it named as index.tpl.
Fourth Step: Create a new file and save it in the templates directory ( this is the directory we created in second step). Copy codes below and paste it to the index.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- we define the meta description block -->
<meta name="description" content="{{onshow.metaDesc}}">
<!-- we define the meta keywords block -->
<meta name="keywords" content="{{onshow.metaKeywords}}">
<!-- we define our title block -->
<title>{{onshow.title}}</title>
<link media="screen" type="text/css" rel="stylesheet" href="css/css.css" />
</head>
<body>
<div id="maincontainer">
<!-- top section -->
<div id="topsection">
<div class="innertube">
<!-- header content -->
<h1>Your Logo Here</h1>
</div>
</div>
<!-- end of top section -->
<!-- this is main content column -->
<div id="contentwrapper">
<div id="contentcolumn">
<div class="innertube">
<!-- main column content -->
<!-- we define our main column content -->
{{onshow.mainContent}}
</div>
</div>
</div>
<!-- end of main content column -->
<!-- this is right column content -->
<div id="rightcolumn">
<div class="innertube">
<!-- right column content -->
<!-- we define our right column content -->
{{onshow.rightContent}}
</div>
</div>
<!-- end of right column content -->
<!-- footer section -->
<div id="footer">
<!-- footer content -->
<!-- we define our footer content -->
{{onshow.footerContent}}
</div>
<!-- end of footer section -->
</div>
</body>
</html>
Simple concept we need to grasp on an instant.. this code {{onshow.footerContent}} is the tinyButStrong template syntax. Yes we don't need to have $ infront of it., but instead we just use the "onshow.whatEverIsTheNameOfVariable_In_PHP_File".
Speaking of the TBS syntax, unlike smarty TBS is a lot simple and easy to understand.
Fifth Step: Create a directory called "css", and in this directory save codes below as css.css
body{
margin:0;
padding:0;
line-height: 1.5em;
}
b{font-size: 110%;}
em{color: red;}
#maincontainer{
width: 840px; /*Width of main container*/
margin: 0 auto; /*Center container on page*/
}
#topsection{
background: #EAEAEA;
height: 90px; /*Height of top section*/
}
#topsection h1{
margin: 0;
padding-top: 15px;
}
#contentwrapper{
float: left;
width: 100%;
}
#contentcolumn{
margin-right: 200px; /*Set right margin to RightColumnWidth*/
}
#rightcolumn{
float: left;
width: 200px; /*Width of right column*/
margin-left: -200px; /*Set left margin to -(RightColumnWidth) */
background: #FDE95E;
}
#footer{
clear: left;
width: 100%;
background: black;
color: #FFF;
text-align: center;
padding: 4px 0;
}
#footer a{
color: #FFFF80;
}
.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
}
That's it for now. Thank you very much for reading :). I hope you enjoy this simple and a borderline tutorial, and I am hoping you will learn something from it as well. For intermediate implementation, you can visit my boring blog. Search for it somewhere, because I don't have the habit of posting a link to my site for my own personal gain. I would only add my affiliation to my own site , solely for the copyright purposes only.