User Tools

Site Tools


en:public:developer:template_system:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:public:developer:template_system:start [2012/11/20 11:28]
admin [Why is separating PHP from templates important?]
en:public:developer:template_system:start [2012/11/20 11:38] (current)
admin
Line 41: Line 41:
   * **SANDBOXING**: When PHP is mixed with templates, there are no restrictions on what type of logic can be injected into a template. ArKadia insulates the templates from PHP, creating a controlled separation of presentation from business logic. ArKadia also has security features that can further enforce granular restrictions on templates.    * **SANDBOXING**: When PHP is mixed with templates, there are no restrictions on what type of logic can be injected into a template. ArKadia insulates the templates from PHP, creating a controlled separation of presentation from business logic. ArKadia also has security features that can further enforce granular restrictions on templates. 
  
-===== Templates =====+For a syntax comparison of PHP vs ArKadia, see [[Syntax Comparison]]. 
  
-Template is simply a text file. It can generate any text-based format (HTML, XML, CSV, etc.). 
-A template contains variables, which get replaced with values when the template is evaluated,  
-and tags, which control the logic of the template. Below is a minimal template that illustrates a  
-few basics. Each element will be explained later in this document.: 
  
-<code html> +===== Web designers and PHP =====
-<#doctype> +
-<html> +
-  <head> +
-    <#meta_title> +
-    <#meta_description> +
-  </head> +
-  <body> +
-    <#frame name="topframe"> +
-  </body> +
-</html> +
-</code>+
  
-Why use text-based template instead of an XML-based one (like Zope's TAL)We wanted ArKadia's template  +A common question: "Web designers have to learn syntax anyways, why not PHP?" Of course web designers  
-language to be usable for more than just XML/HTML templatesWe use it for emailsJavaScript and CSV.  +can learn PHP, and they may already be familiar with itThe issue isn't their ability to learn PHP, it  
-You can use the template language for any text-based format.+is about the maintenance of PHP mixed with HTML. **<#tags>** are simpler, more intuitive, and less fragile  
 +than PHP statementsTemplates also restrict what can be put in a template. PHP makes it too easy to add  
 +code into templates that doesn't belong there. You could teach designers the rules of application design,  
 +but this is should be unnecessary (now they are developers!) The PHP manual is intended for developers.  
 +Designers would only need a small fraction of this manual, and it doesn't make it easier for them to find  
 +what they need. ArKadia gives web designers exactly the tools they need, and gives developers fine-grained  
 +control over these tools.
  
-===== Variables =====+===== Implementation is Important =====
  
-Variables look like this: <#variable>. When the template engine encounters variableit  +Although ArKadia gives you the tools to make clean separation of presentation from application code,  
-evaluates that variable and replaces it with the result. Variable names consist of any  +it also gives you plenty of room to bend those rulesA poor implementation (i.einjecting PHP in  
-combination of alphanumeric characters and the underscore ("_")The dot (".") also appears  +templateswill cause more problems than the presentation separation was meant to resolveThe  
-in variable sections, although that has a special meaning, as indicated belowImportantly,  +documentation does a good job of indicating what things to watch out forAlso see the [[Best  
-you cannot have spaces or punctuation characters in variable names. +Practices]] section 
-  +
-Use a dot (.) to access attributes of a variable<#section.title> will be replaced with the  +
-title attribute of the section objectIf you use a variable that doesn't exist, the template  +
-system will insert '' (the empty string) by default. +
-  +
-===== Filters =====+
  
-You can modify variables for display by using filters. Filters look like this: <#name lowercase="1">  +===== What does ArKadia look like, and how do I use it? =====
-This displays the value of the <#name> variable after being filtered through the lower filter +
-which converts text to lowercase. To give you a taste of what's available, here are some of the more  +
-commonly used template filters:+
  
-=== default ===+The [[Crash Course]] section gives a good overview how ArKadia is typically implemented in a PHP application. 
  
-If a variable is false or empty, use given default. Otherwise, use the value of the variable +===== How does it work? =====
-For example: +
-<code html> +
-<#value default="nothing"> +
-</code>+
  
-=== lowercase ===+Under the hood, ArKadia compiles copies of the templates as PHP scripts. This way you get the benefits  
 +of both template tag syntax and the speed of PHP. Compilation happens once when each template is  
 +first invoked, and then the compiled versions are used from that point forward. ArKadia takes care  
 +of this for you, so the template designer just edits the ArKadia templates and never has to manage  
 +the compiled versions. This approach keeps the templates easy to maintain, and yet keeps execution  
 +times extremely fast. Since the compiled versions are PHP, op-code accelerators such as APC or  
 +ZendCache continue to work on the compiled scripts. 
  
-=== uppercase ===  +===== Why not use XML/XSLT syntax? =====
- +
-=== xmlencode ===  +
- +
-=== htmlencode ===  +
- +
-=== httpencode ===  +
- +
-=== JavascriptEncode ===  +
- +
-=== rtfencode === +
  
 +There are a couple of good reasons. First, ArKadia can be used for more than just XML/HTML based 
 +templates, such as generating emails, javascript, CSV, and PDF documents. Second, XML/XSLT syntax 
 +is even more verbose and fragile than PHP code! It is perfect for computers, but horrible for humans. 
 +ArKadia is about being easy to read, understand and maintain. 
en/public/developer/template_system/start.1353396511.txt.gz · Last modified: 2012/11/20 11:28 by admin