Skip to content

Instantly share code, notes, and snippets.

@whatnickcodes
Created December 19, 2012 22:37
Show Gist options
  • Save whatnickcodes/4341185 to your computer and use it in GitHub Desktop.
Save whatnickcodes/4341185 to your computer and use it in GitHub Desktop.
stencil awesomeness
<?php
//in stencil lib, function paint(). I added this
foreach ($this->slice as $key => $value)
{
if (is_array($value))
{
foreach ($value as $k => $v)
{
$this->data[$k] = $this->CI->load->view('slices/'.$v, $this->data, TRUE)."\n";
}
}
elseif (!is_numeric($key))
{
$this->data[$key] = $this->CI->load->view('slices/'.$value, $this->data, TRUE)."\n";
}
else
{
$this->data[$value] = $this->CI->load->view('slices/'.$value, $this->data, TRUE)."\n";
}
}
//Which now means slices are work a little more awesomely.
//You can now assign variable names... ex:
<?php
//this works the same
$this->stencil->slice('head');
//then in any view (slice, layout, page) you get ---- $head variable to put where you want
//this wrks the same
$this->stencil->slice('header');
$this->stencil->slice('footer');
//then in any view (slice, layout, page) you get ---- $header, $footer
//this works same -- INDEXED array
$this->stencil->slice(array('header', 'footer'));
$this->stencil->slice('whatever');
//then in any view (slice, layout, page) you get ---- $header, $footer, $whatever
//But now!!!!! You can pass ASSOCIATIVE array. Wahoo!
$this->stencil->slice(array('variable_name' => 'slice_name'));
//then in any view (slice, layout, page) you get ---- $variable_name
//super example 1
$this->stencil->slice('head');
$this->stencil->slice('header');
$this->stencil->slice('footer');
$this->stencil->slice(array('sidebar' => 'sidebar1'));
//then in any view (slice, layout, page) you get ---- $head, $header, $footer, $sidebar
//super example 2
$this->stencil->slice(array(
'head',
'header',
'footer',
array(
'sidebar' => 'sidebar2'
)
));
$this->stencil->slice('cat');
//then in any view (slice, layout, page) you get ---- $head, $header, $footer, $sidebar, $cat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment