Go inside the template

I use the same template library as the fil sturgeon, and I have the following layout for my control panel. I get this error. I ran var_dump in the template variable inside the control panel controller, and it showed the control panel view line, but when I do the same inside the content view, it says that there was no body index. I would like to know how to pass data to a content view.

Any ideas for me?

Severity: Notice Message: Undefined index: body Filename: partials/content.php Line Number: 8 

Control panel controller

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Controlpanel extends Backend_Controller { public function __construct() { parent::__construct(); } public function index() { $this->template ->title('Control Panel') ->set_layout('controlpanel') ->set_partial('header', 'partials/header') ->set_partial('sidebar', 'partials/sidebar') ->set_partial('breadcrumbs', 'partials/breadcrumbs') ->set_partial('content', 'partials/content') ->set('user_data', $this->users_model->get($this->session->userdata('uid'))) ->build('dashboard'); } } 

content.php

 <div id="content"> <!-- Insert Header --> <?php echo $template['partials']['breadcrumbs']; ?> <div class="separator bottom"></div> <?php echo $template['body']; ?> </div> 

I tried to study this and still have not found a solution. I was hoping someone else would see something that I did not know.

+4
source share
2 answers

I also use its library and get some ploblems when passing objects through

 $this->template->set('data_name', $my_object); 

just add it to the array.

 $this->template->set('data_name', (array) $my_object); 
+1
source

The following works for me:

 $this->template->set('body', $body); 

Then, in my opinion, (using the PyroCMS lex parser):

 {{ body }} 

Alternatively, you can assign an array to the set method:

// $ page from db request

 $this->template->set('page', $page); 

Then in the view:

 {{ page->body }} 
+1
source

Source: https://habr.com/ru/post/1484730/


All Articles