is there a way to make template but not render it in plates php

141 views Asked by At

Is there a way in plates php where I can make a template in a controller but render it using another controller. Say I have two controllers. HeaderController and a SearchController.

SearchController

class Search extends \system\core\BaseController
{
    public function Index()
    {
        $data['text_search'] = 'Search..';

        // This $this->template->render down below is what I don't want now
        // okay asign the data but do not display the template yet
        echo $this->template->render('common/search', $data);
    }
}

The dummy SearchController should assign $data to the template search.tpl but not render/display the template.

This is where I will be calling the above controller

HeaderController

class HeaderController extends \system\core\BaseController
{
    public function Index()
    {
        // Some codes

        // Call / load the SearchController and asign it to $data['search'] 
        $data['search'] =  $this->load->controller('common/SearchController');

        // and then pass all $data and render/display it.
        echo $this->template->render('common/header', $data);
    }
}

Is there a way of doing it?

1

There are 1 answers

1
tereško On BEST ANSWER

The issue actually comes from the fact, that you are using echo within your class. If your "controllers" (well, they actually seem to be a combination of view and controller) were to return either the content or Response class instance, then you problem should disappear.