Agile Toolkit View Digest

View and AbstractView will replace tag <?$_name?> with the name of current object. They will also look for all occurrences of “template” tag and pass content of those tags through “locateURL” method of pathfinder.

 

$page->add('H1')
  ->set('View Demo');
////////////////////////////////
$page->add('Frame')
  ->setTitle('Sample Frame');
  ->add('LoremIpsum');

////////////////////////////////

 $li = $page->add('LoremIpsum')
 ->setLength(1,15);
 $page->add('Button')->set('Refresh')
 ->js('click',$li->js()->reload());

////////////////////////////////

$page->add('Text')
 ->set('sample text');
//To keep you safe from SQL injection, Text will automatically escape htmlentities.
//To avoid escaping use setHtml() method or you can use "Html" class instead.
////////////////////////////////
//Changing button system-wide:
class Button extends View_Button {}
////////////////////////////////////////
$button->setIcon('icon-name');

 

Re-usable HTML chunk of code:

$page->add('View',null,'corner',array('view/snippet'));

HTML snippet with enabled logic

What if your HTML code needs some additional logic? It’s then better to create a separate class for your view:

class Alex extends View {
    public $float='right';
    function init(){
        parent::init();
        $this->setElement('img');
        $this->setAttr('src',$this->api->url('template','images/PinkElephant.jpg'));
    }
    function render(){
        $this ->addStyle('float',$this->float);
        parent::render();
    }
    function align($side){
        $this->float=$side;
        return $this;
    }
}

Special page layout

Suppose your designer wants to put something special on one of your application pages. Redefine defaultTemplate() of your page first:

class page_test extends Page {
    function init(){
        parent::init();
        $this->add('LoremIpsum');
    }
    function defaultTemplate(){
        return array('page/test');
    }
}

Put the code designer asked you to use inside templates/default/page/test.html, but don’t forget to add <?$Content?> tag. It’s recommended that you also use the id=”<?$_name?> for the top-most element of template. That’s not mandatory but will enable event binding and reloading.