Welcome Guest, Not a member yet? Register   Sign In
Template Parser
#1

[eluser]ann91[/eluser]
hello guys, i have problem about this code. i use codeigniter 2.0.2. In this case, i want to make template with class Template Parser.

Code:
function index()
  {
    $data = array( 'title'   => 'Welcome to my webSite',
                   'content' => 'This is the Content'    
                 );
     $this->parser->parse('main', $data);
  }
and the function Model
Code:
function getRecentPost()
{
  $this->db->select('*');
  $this->db->from('post p');
  $this->db->where('active_post',1);   //
  $this->db->order_by('p.post_id','desc');
  $this->db->limit(5);  //
  return $this->db->get();
}


if i want to add <b>Postmodel</b> into <b>content</b> pseudo-variables, how i write it??

in codeigniter 1.7.2, the code like this..

Code:
function index()
    {
        $data['title']="Welcome to My Website"; //
        $data['content']=$this->postmodel->getRecentPost(); //
        $this->load->view('main',$data);
    }
#2

[eluser]InsiteFX[/eluser]
In your View:
Code:
{title}
{content}

InsiteFX
#3

[eluser]darrentaytay[/eluser]
Instead of calling:

Code:
$this->load->view('main', $data);

You need to load the Template Parser Class and call the parse function:

Code:
$this->load->library('parser');
$this->parser->parse('main', $data);

Then as InsiteFX said, use the pseudo variables in your main view.

Code:
{title}
{content}
// or any other variable passed via data




Theme © iAndrew 2016 - Forum software by © MyBB