File: documentation/en/

Recommend this page to a friend!
  Classes of Fernando Val  >  Springy  >  documentation/en/  >  Download  
File: documentation/en/
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Springy
Microframework for Web application development
Author: By
Last change: Documentation
Date: 1 year ago
Size: 1,929 bytes


Class file image Download



Views are part of MVC architecture of the framework. They are code responsible for presenting data to end users, usually files containing HTML code and special codes parsed by a template engine.

In this framework you can use two different template engines: Twig or Smarty.

Creating Views

The files with templates for the views, must be placed inside the templates directory. Each template drive uses a different suffix in file name. The files for Twig driver must end with .twig.html and the files for Smarty driver must end with .tpl.html.

Sample of a template to Twig driver.

<!DOCTYPE html>
        <title>My Webpage</title>
        <ul id="navigation">
        {% for item in navigation %}
            <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
        {% endfor %}

        <h1>My Webpage</h1>
        {{ a_variable }}

Using Templates

Once you have created your template file, you will need a controller to print its content. All you need is create a Springy\\Template object and use its methods.

Sample how to use a template view:

    $tpl = new Template('my-template');
    $tpl->assign('var', 'a value to the variable');

If your controller extends Springy\\Controller class, you can use the protected method _template() to create the template object, like this:

    $this->template->assign('var', 'a value to the variable');

For more information send a message to info at phpclasses dot org.