Hi!
Okay, i try to explain what i mean with this topic :)
I have expand the view with some additional features to build a small templating-system. Here is the code. It's a little bit messe becouse of a rewriting an older idea.
PHP Code:
class PAGES_Loader extends CI_Loader
{
// Page content
private $page = array();
// View data
private $temp = array();
private function add_head ($key, $data)
{
$this->page['head'][$key] = $data;
}
public function add_element ($key, $temp, $data)
{
$this->page['body']['elements'][$key] = $this->view($temp, $data, TRUE);
}
public function create_view ($data)
{
// DINO
$this->page['body']['elements']['navigator'] = $this->view('theme/test1/navigator_on', '', TRUE);
// Load website template
$this->page['body']['template'] = $this->view($data['template'], $this->page['body']['elements'], '', TRUE);
$this->add_head('description',$data['description']);
$this->add_head('keywords',$data['keywords']);
// Load page templates
$this->temp['header'] = $this->view('page/header', $this->page['head'], TRUE);
$this->temp['body'] = $this->view('page/body', $this->page['body'], TRUE);
// Go
$this->view('page', $this->temp);
}
}
Now i use my methods to add data to my template in my controller
PHP Code:
public function erstellen ($box_id)
{
// Check content
[...]
// Element: Formular
$this->load->add_element(
'card_form',
'theme/test1/karte/form',
$this->build_form(NULL, $box_id)
);
// Element: Cardlist
$cards['cards'] = $this->karte_model->read_cards($box_id);
// Put all to the element
$this->load->add_element(
'cards_list',
'theme/test1/karte/list',
$cards
);
// Load template
$this->load->create_view($this->members_model->read_members_home()); // = template/test1/members
}
First, the page.php will be loaded. It only contains two variables for header and body.
PHP Code:
<!DOCTYPE html>
<html lang="en">
<?php echo $header; ?>
<?php echo $body; ?>
</html>
Header and Body are part of my "template-engine". Header is is only html-code (as you can find in the next code-block) and body loads the elements.
Code:
<body id="page-top" class="index">
<?php echo $template; ?>
<script src="assets/theme/merlin/js/jquery.min.js"></script>
<script src="assets/theme/merlin/js/bootstrap.min.js"></script>
<script src="assets/theme/merlin/js/isotope.pkgd.min.js"></script>
<script src="assets/theme/merlin/js/imagesloaded.min.js"></script>
<script src="assets/theme/merlin/js/jquery.scrollTo.min.js"></script>
<script src="assets/theme/merlin/js/jquery.nav.min.js"></script>
<script src="assets/theme/merlin/js/jquery.appear.min.js"></script>
<script src="assets/theme/merlin/js/twitterFetcher.min.js"></script>
<script src="assets/theme/merlin/js/script.js"></script>
</body>
template only shows what elements are available. Its the file members.php which is loaded as last view in my first listing.
PHP Code:
<?php echo $navigator; ?>
<?php if (isset($form)) echo $form; ?>
<?php if (isset($boxes)) echo $boxes; ?>
<?php if (isset($box_details)) echo $box_details; ?>
<?php if (isset($card_form)) echo $card_form; ?>
<?php if (isset($cards_list)) echo $cards_list; ?>
<?php // if (isset($cards_list)) echo $cards_list; ?>
<footer id="footer">
<div class="container">
[... SOME MORE CODE ...]
</div>
</div>
</div>
</footer>
But if i open my html-source in my browser, i found this:
Code:
[... MY ELEMENTS FROM THE LAST LISTING (members.php)...]
<div class="loader">
<div class="fading-line"></div>
</div>
<div id="navbar-top">
[... AND MORE CODE ...]
</div>
</div>
</div>
</footer>
[... FILE PAGE.PHP with HEADER.PHP and BODY.PHP ...]
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Merlin HTML/CSS template">
<meta name="author" content="Hasan Alibegic">
<link rel="shortcut icon" href="/qube2_ci/application/view/theme/ico/favicon.ico">
<title>Merlin</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,600">
<link rel="stylesheet" href="/qube2_ci/assets/theme/merlin/css/bootstrap.min.css">
<link rel="stylesheet" href="/qube2_ci/assets/theme/merlin/css/style.css">
<link rel="stylesheet" href="/qube2_ci/assets/theme/merlin/css/animate.min.css">
<link rel="stylesheet" href="/qube2_ci/assets/theme/merlin/css/font-awesome.min.css">
<!--[if lt IE 9]>
<script src="/qube2_ci/assets/theme/merlin/js/html5shiv.js"></script>
<script src="/qube2_ci/assets/theme/merlin/js/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top" class="index">
[... HERE SHOULD THE ELEMENTS BE LOADED ...]
<script src="assets/theme/merlin/js/jquery.min.js"></script>
<script src="assets/theme/merlin/js/bootstrap.min.js"></script>
<script src="assets/theme/merlin/js/isotope.pkgd.min.js"></script>
<script src="assets/theme/merlin/js/imagesloaded.min.js"></script>
<script src="assets/theme/merlin/js/jquery.scrollTo.min.js"></script>
<script src="assets/theme/merlin/js/jquery.nav.min.js"></script>
<script src="assets/theme/merlin/js/jquery.appear.min.js"></script>
<script src="assets/theme/merlin/js/twitterFetcher.min.js"></script>
<script src="assets/theme/merlin/js/script.js"></script>
</body>
</html>
My problem is, that my elements not in the body-file. It loads all an the right place (header and body in page.php, and also the members.php is loaded, but not in body. Why this? I can't understand at the moment... If you have a hint for me ... thanks a lot :)[/php]