Muestra las diferencias entre dos versiones de la página.
Próxima revisión | Revisión previa | ||
views [2016/08/22 18:12] luchothoma creado |
views [2016/12/30 18:42] (actual) |
||
---|---|---|---|
Línea 35: | Línea 35: | ||
class MainController { | class MainController { | ||
- | public function index() { | + | public function index() { |
- | + | ||
View::render('hello', array( | View::render('hello', array( | ||
'title'=>'Amazing!', | 'title'=>'Amazing!', | ||
- | 'content'=>'That's cool !' | + | 'content'=>"That's cool !" |
) | ) | ||
- | ); | + | ); |
- | + | ||
} | } | ||
} | } | ||
Línea 54: | Línea 52: | ||
<head><title> <? echo $title; ?> </title></head> | <head><title> <? echo $title; ?> </title></head> | ||
<body> | <body> | ||
- | <b><? echo $title; ?></b> | + | <b><? echo $content; ?></b> |
</body> | </body> | ||
</html> | </html> | ||
</code> | </code> | ||
+ | |||
+ | **Views inside other ones** | ||
+ | When you for some reason want to extend one view adding other view inside this, you can override the content for the new view or prepend the new view to the actual content: | ||
+ | <code php | base.php> | ||
+ | <?php use Salem\View; ?> | ||
+ | <!DOCTYPE html> | ||
+ | <html> | ||
+ | <head><title>Base VIEW</title></head> | ||
+ | <body> | ||
+ | <?php View::new_section('important', true); ?> | ||
+ | <p>Boring default content</p> | ||
+ | <p>This will be deleted only if we call a view that fill the content of this section</p> | ||
+ | <?php View::end_new_section(); ?> | ||
+ | |||
+ | <?php View::new_section('optional', false); ?> | ||
+ | <p>Something that stay here.</p> | ||
+ | <p>-May be some text will appear under this text-</p> | ||
+ | <?php View::end_new_section(); ?> | ||
+ | </body> | ||
+ | </html> | ||
+ | </code> | ||
+ | And now the view that is going to extend this base view: | ||
+ | <code php | extra.php> | ||
+ | <?php use Salem\View; View::extend('base'); ?> | ||
+ | |||
+ | |||
+ | <!-- Important Content --> | ||
+ | <?php View::section('important'); ?> | ||
+ | |||
+ | <p>Hello, World!</p> | ||
+ | |||
+ | <?php View::end_section(); ?> | ||
+ | |||
+ | |||
+ | <!-- Optional --> | ||
+ | <?php View::section('optional'); ?> | ||
+ | |||
+ | <p>WOOOoooOOOooOooo</p> | ||
+ | |||
+ | <?php View::end_section(); ?> | ||
+ | </code> | ||
+ | |||
+ | Finally, when you want to call this extended view you must do: | ||
+ | |||
+ | <code php| maincontroler.php> | ||
+ | <?php | ||
+ | namespace Controller; | ||
+ | use Salem\View; | ||
+ | |||
+ | class MainController { | ||
+ | |||
+ | public function index() { | ||
+ | |||
+ | View::render('extra'); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | ?> | ||
+ | </code> | ||
+ | ---- | ||
+ | [[documentation|Go back to Documentation]] |