How To Create A Template For A Website

Table of contents:

How To Create A Template For A Website
How To Create A Template For A Website

Video: How To Create A Template For A Website

Video: How To Create A Template For A Website
Video: How to Build a Website Using HTML Theme/Template 2024, May
Anonim

If you are planning a site consisting of many pages, it is extremely important to know how to make a site template. It will make life easier for both the layout designer and the programmer.

How to create a template for a website
How to create a template for a website

What is a website template?

Any site consists of many pages, each of which contains the same elements: service information, menu, identical design, and so on. If you set yourself the goal of changing a similar element on the entire site - say, adding a new item to the menu - then you will have to perform this action on each page. If there are 10 of them on the site, then the task is not too difficult. What if 100 or more?

A template is a kind of layout that implements the logic of displaying a material. Here you can set the display location of the menu, site header, main content, and so on. The very content of the elements written in the template is set in the script or through the functionality provided by the content management system.

You can imagine a couple of documents as a template. One file contains markup. This is the layout itself, where the specific location of this or that content is indicated. The second file is responsible for what exactly will be displayed. The task of the second document is to analyze the layout file and substitute the real values of the variables.

These two documents are inseparable, because otherwise they are not so interesting: if you run the template file, it will not display any useful information. The same will happen if you run the handler script without the layout itself.

How to create a website template?

Creating a site page layout is reduced to creating a simple html document, which contains the logic for displaying page elements. At the same time, you need to create a file that controls the display of the template. This file will contain the real values of the variables.

This work is quite time consuming, so you can use a ready-made template engine. Smarty and Twig are examples. In this case, it is enough to download the distribution kit of the template engine, and, according to the instructions, install it on the server. In this case, there is no need to create a file responsible for displaying real variables, since it has already been created - this is the distribution itself, that is, a set of files. You only need to create page layouts.

It should be borne in mind that modern template engines are quite versatile. You can talk about a separate programming language for templates, since in layouts you can enter a display by condition, in a loop, etc.

Conclusion

Creating a template is a very good way to separate display logic from application logic. This makes it easier for the layout designer and simplifies the work of the programmer.

Recommended: