putThemeContent Method

The putThemeContent method used for load a view component file in current theme. This method support stack for loading another view component.

Basic Usage

Here is the basic usage of putThemeContent method from SENE_Controller class.

$this->putThemeContent(string $content_location[, array $data]): $this

Parameters

This method has required 1 parameter that is $content_location.

$content_location

The $content_location value can be a string that indicates view component location related to current theme. This value does not need .php suffix.

$data

The $data values contain array of array that will be passed to view as a variable. The array key from this value will be parsed as name of a variable.

Example

Here is the example implementation of putThemeContent method.

File and Directory structures

Before implementing the codes, we have to understand the file and directory structure that will used in example.

app/
└── view/
 └── front/
  ├──  home/
  | ├──  slider.php
  | └──  three_values.php
  └──  page
    └──  col-1.php

The Controller

On this code example shows implementation of putThemeContent method and how to passing variable to it.

class Home extends SENE_Controller
{
  public function __construct()
  {
    parent::__construct();
    $this->setTheme('homepage');
  }
  public function index()
  {
    $data = array();
    $data['example'] = 'this is example';
    $this->putThemeContent('home/slider',$data);
    $this->putThemeContent('home/three_values',$data);
    $this->loadLayout('col-1',$data);
  }
}

View component

From this example, how view called $data as a variable on home/slider.php view component source codes.

<div>
  <h1>This is parsed value from data <?=$example?></h1>
</div>

Info

The putThemeContent , putJsContent and loadLayout methods has the ability to buffer view components. So the view component(s) that collected from the methods are not directly show up on browser, but only displayed while called render method.