Archive for the ‘Tutorials’ Category

Setting up Template Blocks for OFFLINE use

Tuesday, June 24th, 2008

If you want to use Template Blocks on your local server as a web design/compiling tool, this is the guide for you. For users that don’t have a local server but want to work with the template engine offline, XAMPP is recommended as a light-weight and efficient solution.

Some of this information may be different depending on the platform you are working (Windows, Linux, Mac OS). In any case you will need Apache installed and running beforehand.

To access Template Blocks locally you will need to map a domain name to point to its location. That way you won’t have to install Template Blocks on the root of your server or fight with custom paths that may cause glitches to the engine. Instead you can work with Template Blocks on a top domain level, wherever it is on the local server.

Setting up a VistualHost in Apache

Go to where your Apache is installed and find to the “conf/extra” sub-folder. Open “httpd-vhosts.conf” in a text editor. You’ll find some commented examples how to setup a VirtualHost entry - write at the bottom of the file your own. These are the ones I use on my setup:

NameVirtualHost 127.0.0.1
 
<VirtualHost 127.0.0.1>
  DocumentRoot "C:\Server\htdocs"
  ServerName localhost
</VirtualHost>
 
<VirtualHost 127.0.0.1>
  DocumentRoot "C:\Server\htdocs\templateblocks"
  ServerName templateblocks.dev
</VirtualHost>

Note that you should change the IP (127.0.0.1) if your server has another one and the document path and domain name as suited.

For Windows users

Additionally you’ll have to tell windows to redirect the domain name (templateblocks.dev) to the local server and not make a DNS look up for it online.

For this go to “C:\WINDOWS\system32\drivers\etc\” and open the “hosts” file in a text editor. There you will possibly find a line already redirecting yo your local server, mine is:

127.0.0.1       localhost

Under that line make a new line for your custom domain (templateblocks.dev)

127.0.0.1       templateblocks.dev

Save that file. Now when you enter “templateblocks.dev” from a browser windows knows to redirect it to your local server and your local server knows to redirect it to the appropriate folder.

Re-start Apache and load a web browser to you new a top level domain.

Enjoy working with Template Blocks offline.

The setup process

Tuesday, May 6th, 2008

A presentation of the basic setup process, recorded in real-time:

Pop-up notes make up for the absence of a voice. Being a relatively easy process it doesn’t make that much of a difference anyway - in fact the text is better comprehended and memorized. Intended for first-time users and novice web developers.

Introductory Tour

Tuesday, May 6th, 2008

An brief introduction to the very basics of Template Blocks, presented in an ad form:

Redirection/Wrapping Issues

Friday, April 25th, 2008

- How does the redirection work?
To make the redirection work you’ll need the .htaccess file included in the archive and upload it at the root of your domain name along with the index.php file. Both need to be present for the redirection to work.

- How does the “index.php” file in the root works?
The index.php handles all the redirection after the request passes from the .htaccess file. Based on the URL the sctipt will find the section name and the parent section name (if any) and submit that information to the “template/index.php” which resources the actual data. Note that the script can only handle pages created though the template engine’s administration interface. If the engine doesn’t find a section assigned to that request it will redirect the visitor to the index page.

- What is the .htaccess commands mean?
This is the code included in the .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
 
</IfModule>

Basically it says that if a file or directory from the URL requested is not actually there then redirect to the index.php on the same level to handle the request. It’s the same code that Wordpress uses for its search engine friendly URLs…

- I can’t get the redirection to work! I’m only seeing the index page.
Make sure that mod_rewrite is loaded for your server setup. That’s the module the .htaccess file uses for the redirection commands. Go to where your Apache is installed and move to the “conf/” sub-folder. Open “httpd.conf” in a text editor.
Find the line

LoadModule rewrite_module modules/mod_rewrite.so

and make sure it’s uncommented (no # in front of it). Save the file. Re-start Apache. Now redirections should work.

- What information does the engine need for a redirection?
All information is passed through the URL, the section name and it’s parents in an hierarchical order. It will then compile all the right pieces and present the template automatically.

- Can I load the template manually?
To load a template from your script all you need to know is the section slug you have created in Template Blocks for that script. Then load it in the variable $GLOBALS[’section’] and include the ‘/template/index.php’ file. Now you have the template in two variables:
$GLOBALS[’template-pre’] - the template before the content
$GLOBALS[’template-post’] - the template after the content
It’s up to you to use the template however you want in your script.

- The variable $GLOBALS[’section’] is reserved by my script. What do I do?
In this case you can easily change it to anything else you want. Simply open “template/index.php” and replace the $GLOBALS[’section’] to $GLOBALS[’anything_you_want’]. Then assign to that variable the name of the slug for the section that is linked with the script.

Other Issues

Sunday, April 20th, 2008

- Why use separate template engine when Wordpress for example has a perfectly functionable template system itself?
If you are going to use only Wordpress on your site and are happy with all the features it offers then please be my guest - Is a wordpress template and that’s that. But what if one day you decide that you need a forum on your site. And then you add a wiki, and a download directory and so on. Are going to build the template again and again or will you leave it to what looks “close enough”? Repetition of code (even if it’s markup code) only means one thing: tedious updates. This is where Template Blocks comes. You can define the templates you want to use outside the scripts you are using so updating them will become less fustrating - almost joyful one might say…

- How am I going to use Template Blocks offline?
Although Template Blocks can be used as a full-blown template engine - and many will prefer to use it as such, it was created with helping the web designer’s work in mind. In that regards t’s intended for use at the early stages of development where the user is forming the web templates from concept graphics. You’ll need to setup Linux with PHP and MySQL on your computer and setup a web server to work locally. Template blocks may not be a WYSIWYG editor and it’s certainly not a CMS but it can prove to be a valuable a web design tool.

Basic Development

Sunday, April 20th, 2008

- Do I need that “index.php” outside the template folder?
Initially I have to say, yes you do. This file as it parses all the requests that don’t have actual files linked to them (aka 404 errors). As most of the URLs template blocks uses are “imaginary” it needs this parsing mechanism to analyze the URL and load up the correct template accordingly. But as the template engine is working on two levels: 1) providing static content internally and 2) wrapping around other scripts that provide the content externally, you may not need it if you are going to use it just for the second case. The reason it is not needed then is because the URL is parsed by the external script itself and not by index.php.

- Where is the engine? I need to code everything!
Yes, you will need to code - you will need to create markup. Template Blocks works in the background when compiling your template and aims (among others): to free you from the repetitive tasks of compiling the templates manually, to separate your code completely from the template and to help you bring out the logic you have in your mind and convert it in to a real structure effortlessly.

- Can Template Blocks work with another server setup?
At present, the engine works in a PHP-MySQL environment although it is possible to be ported in any platform. At the moment, this development is left for the end users that want these extra features.

- Can I rename the template folder (or put it somewhere else)?
Although the engine by design does give you the possibility to rename the template folder to anything you like it is not recommended as not all functions have been tested thoroughly for any given name or folder level. That means we do not guarantee it will work as well as it does under the “template” folder.

- Can I use variables in my HTML blocks?
Yes, you can use a number of variables and they will be replaced before outputting the content. Call them as such:
$Website = The Website Title
$Template_dir = where Template Block is located (used for paths)
$Title = The title of the section

- I want to have my own PHP classes and reference them in my PHP blocks.
That’s fine. The best way is to create your classes inside the “/template/admin/classes” folder, preferably one file for each different class. Then you can call them from a PHP block as usual…

General Questions

Sunday, April 20th, 2008

- What is Template Blocks?
Template blocks is a visual template engine, built from the ground up to tailor the needs of the new age web community. It is directed for use by professional web developers that want the raw power of creating markup code and script functions but don’t want to get stuck in the little details that are proven to be time consuming and mind numbing.

- Who created this and why?
This script was initially developed by Makis Tracend, a web developer from Sydney, partly out of necessity to use for his own websites and partly to record the logic gathered after years of experience in web designing. It is released to the public in the hopes that the online community would benefit from it as the goal seemed more universal.

- How does this template engine work in a few words?
The basic concept is that any template can be split up in pieces. What we call here blocks. A block can be any self-contained piece of HTML (starting and closing with the same tag) or any other Stylesheet, JavaScript or even PHP script file. You first create the blocks and then by compiling them you create the different templates you are going to use on the site.

- Is Template Blocks like a CMS?
No, Template Blocks is not just another CMS. It’s a template engine. In fact you can wrap Template Blocks around any CMS, blog or other online application, separating the template creation from the content once and for all.

Setup / Update

Sunday, April 20th, 2008

- Can I install the database tables manually?

Yes, you can do that through an interface like PhpMyAdmin or a shell connected to your database. Find the file “mysql.sql” in the setup folder which contains all the SQL needed to create the tables and insert the dummy content.

- Why not upload the assets folder when upgrading?

This folder contains dummy content for new websites. Having used Template Blocks before means that most of your custom template work will reside there. You wouldn’t want to overwrite that, right?

- I can’t load the setup page! (Output: Could not save your data…)

The most common case is that you are using an unpatched version of Internet Explorer 6. Ajax calls is known to have problems with IE6 that is prior to the XP SP2 release. The only solution is to patch your IE6 to the latest version or upgrade to a more recent version of Internet Explorer.

You are currently browsing the archives for the Tutorials category.