Welcome Guest, Not a member yet? Register   Sign In
How to insert view into another view?
#10

Thank you all for answers!

I wrote my code using the third parameter of Load::view('path_to_view1" , $data , true)

It looks like this:

Controller
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Main extends CI_Controller {

    public 
$template 'template';        //Default template
    
public $content '';                //Content view
    
    
public $data = array(
        
'title' => 'Site_name',            //Default title
        
'h1' => 'Site_name'                //Default h1
        // ... Other values
    
);
    
    
    
//Apply settings
    
public function base()
    {
        
//Content view
        
$this->data['content'] = $this->load->view($this->content$this->datatrue);

        
//Default template
        
$this->load->view($this->template,$this->data);
    }
    
    
    
//Some page
    
public function index()
    {
        
//Page data
        
$this->data['title'] = 'Title for this psge';
        
$this->data['h1'] = 'H1 for this psge';
        
// ... Other values
        
        //Content view
        
$this->content 'index_view';
        
        
//Apply settings
        
$this->base();
    }
    
    


View template.php
Code:
<!doctype html>
<head>
    <title><?= $title ?></title>
</head>
<body>
<!-- Head and menu html -->
...
<!-- /Head and menu html -->

<?= $content ?>

<!-- Footer html -->
...
<!-- /Footer html -->
</body>
</html>

Thank you!
Reply


Messages In This Thread
How to insert view into another view? - by Kostia - 12-10-2015, 01:27 AM
RE: How to insert view into another view? - by Kostia - 01-09-2016, 08:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB