Smarty

format_list_bulleted Contenido keyboard_arrow_down
ImprimirCitar

Smarty is a templating engine for PHP, that is, it separates PHP code, such as business logic, from HTML code, such as presentation logic, and generates web content by placing Smarty tags in a document. It is licensed under the GNU Lesser General Public License.

It is common that in large projects the role of graphic designer and programmer are covered by different people, however PHP programming tends to combine these two tasks in one person and within the same code, which brings I get great difficulties when it comes to changing any part of the page design, because you have to dig through the scripts to modify the presentation of the content, Smarty aims to solve this problem.

Features

  • Regular expressions
  • Loops foreach, while
  • Conditional sentences if, elseif, else
  • Variables modifiers (e.g.: {$variable)
  • Functions created by the user
  • Assessment of mathematical expressions in the template

Criticism

There are more template systems for PHP, but this seems to be the most advanced and most frequently developed. There are also detractors of these techniques who claim that they make web development to a certain degree more complex, due to the need to learn another (pseudo) language.

Detractors of this idea are based on the fact that, precisely, the PHP language was born as a fast language for small-scale web development. As systems of separation in layers are emerging that try to discipline the programming methodologies involved in development with PHP a bit, but that do nothing other than get closer and closer to other tools already existing in other more complex and thought-out development environments. from its origins to larger projects, such as J2EE (Java),.NET (C#) or Django (Python).

Example

index.php
require_once("smarty/Smarty.class.php");// Install Smarty Class$smarty = new Smarty();// Setting Smarty$smarty- 2005template_dir = "./templates/";$smarty- 2005compile_dir = "./templates_c/";$smarty- 2005config_dir = "./configs/";$smarty- 2005cache_dir = "./cache/";// Set variables to be used in the template$smarty- 2005assign("Name", "José Manuel Pardo Pérez");$smarty- 2005assign("direction", "C/Alpes, 992");// Show template$smarty- 2005display("index.html");
index.html
 backwards!DOCTYPE HTML PUBLIC "-//W3C///DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" .html lang="is" .head .titleUser informationtitle head .body .pUser information:p .pName: {$name}.br / 2005Address: {$direction}
 p body html
HTML output generated
 backwards!DOCTYPE HTML PUBLIC "-//W3C///DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" .html lang="is" .head .titleUser informationtitle head .body .pUser information:p .pName: José Manuel Pardo Pérez.br / 2005Address: C/ Alpes, 992
 p body html

Contenido relacionado

Linked list

In computer science, a linked list is one of the fundamental data structures, and can be used to implement other data structures. It consists of a sequence of...

K-Meleon

K-Meleon is a free web browser based on the Gecko web rendering engine. The goal of K-Meleon is to provide a lightweight browser for Microsoft Windows similar...

File server

In principle, any computer connected to a network, with the appropriate software, can function as a file...
Más resultados...
Tamaño del texto:
undoredo
format_boldformat_italicformat_underlinedstrikethrough_ssuperscriptsubscriptlink
save