php - Load layout once in Fat-Free Framework -


i think should have pretty simple explanation i'm still learning fat-free framework (f3): how render once header , footer , switch out content code selected route? have code:

$f3->route('get /',   function($f3) {     $f3->set('content','views/welcome.htm');     $f3->set('page_head', 'welcome');   } ); 

and if add line:

echo view::instance()->render('layouts/header+footer.htm'); 

either after f3->set calls in route or after $f3->run(); @ end of index.php file, whole page refreshes on route change. can't call echo line above before route code without throwing error in content box.

is there way disable page refreshing? being refreshed because links being interpreted separate pages browser? help!

your question little hazy. try answer in way understand. first index.php

$f3->route('get /',   function($f3) {     $f3->set('content','views/welcome.htm');     $f3->set('page_head', 'welcome');     echo template::instance()->render('layouts/header+footer.htm');   } ); $f3->run(); 

in header+footer.htm

<!doctype html> <html> <head lang="en">     <meta charset="utf-8">     <title>{{@page_head}}</title> </head> <body> <include href="{{@content}}"/> </body> </html> 

your views/welcome.htm can contain anything.

<h1>welcome</h1> <p>you have arrived welcome page</p> 

please remember folders views , layouts should in ui folder

$f3->set('ui','ui/');  

on comment: can access params of request $f3->get('params') or can this.

$f3->route('get /@page',       function($f3,$params) {         $page = $params['page'];         $f3->set('content','views/'. $page .'.htm');         $f3->set('page_head', 'welcome');         echo template::instance()->render('layouts/header+footer.htm');       }     ); 

this should work


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -