Multiple times using Flight::render in framework

952 views Asked by At

I'm trying to build a small website using the Flight php framework. The goal is to have a clear framework using various views.

Until this point everything is working fine, I managed to build a nice framework.php and an content, menu and header view

Flight::render('header', array('heading'=> $page_title), header_content');
Flight::render('menu', array('type'=> 'main menu'), mainmenu_content');
Flight::render('body',   array(), 'body_content');

Flight::render('layout', array('title' => 'Home Page'));

the content is build up of multiple sections (articles) which all have the same layout, now I would like to again use the Flight views to generate those sections. using the following code I can create on section and pass it trough to the 'body'

Flight::render('section',   array('id' => $id), 'section_content');

what is the best solution to add multiple sections to one page?

I've tried to get, in the index.php, the value of $section_content, as variable and using Flight::get('section_content'). both without success. running the Flight::render twice will overwrite the value of $section_content (as expected). Also tried to use an array for $section_content, also without success.

Of course I can find numerous work-around solutions but I'm not going to use them until I'm certain what I want is relay impossible.

1

There are 1 answers

0
Fatih Mert Doğancan On

While you must all section define, you last define your layout render. Like this;

<?php
Flight::route('/', function(){
    //header.php value is $contHeader varriable
    Flight::render('header', array(
        'title' => 'Test title'
    ), 'contHeader');
    //modals.php value is $contModals varriable
    Flight::render('modals', array(), 'contModals');
    //body.end.php value is $contBodyEnd varriable
    Flight::render('body.end', array(), 'contBodyEnd');
    //nav.menu.php value is $contNavMenu varriable
    Flight::render('nav.menu', array(), 'contNavMenu');
    //You must all varriable define in "layout.homepage.php", you can write it with echo statement
    Flight::render('layout.homepage'); //you forget this one
});
?>