mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-27 15:19:54 +02:00
Add new Templating section.
This commit is contained in:
21
_posts/08-02-01-Benefits.md
Normal file
21
_posts/08-02-01-Benefits.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
isChild: true
|
||||
anchor: templating_benefits
|
||||
---
|
||||
|
||||
## Benefits {#templating_benefits_title}
|
||||
|
||||
The main benefit to using templates is the clear separation they create between the presentation logic and the rest of
|
||||
your application. Templates have the sole responsibility of displaying formatted content. They are not responsible for
|
||||
data lookup, persistence or other more complex tasks. This leads to cleaner, more readable code which is especially
|
||||
helpful in a team environment where developers work on the server-side code (controllers, models) and designers work on
|
||||
the client-side code (markup).
|
||||
|
||||
Templates also improve the organization of presentation code. Templates are typically placed in a "views" folder, each
|
||||
defined within a single file. This approach encourages code reuse where larger blocks of code are broken into smaller,
|
||||
reusable pieces. For example, your site header and footer can each be defined as templates, which are then included
|
||||
before and after each page template.
|
||||
|
||||
Finally, depending on the library you use, templates can offer more security by automatically escaping user-generated
|
||||
content. Some libraries even offer sand-boxing, where template designers are only given access to white-listed
|
||||
variables and functions.
|
Reference in New Issue
Block a user