Welcome Guest, Not a member yet? Register   Sign In
Williams Concepts Template + load->vars help
#1

[eluser]Met[/eluser]
hola

Must be missing something.

I quote the reference (http://www.williamsconcepts.com/ci/codei...rence.html )
Quote:"My template uses other variables that aren't necessarily regions. How do I supply those within Template?"

You most likely will use variables in your main template that aren't content regions. For example, you might have a $body_id variable that you apply to the <body> element that you use in your CSS to apply styles to specific pages. This certainly could be a region, but it wouldn't quite fit the metaphor.

To supply these variables to your master template, use CodeIgniter's $this->load->vars() mechanism.

my code:
Code:
<?php

class Site extends Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->library('template');    
    }
    
    function index()
    {
        $this->template->write('title', 'My title');
        
        $data['active']='home';
        // i want to pass the template $active so the appropriate navigation link gets the "active" class appended to it.

// now i guess I'm missing something:

        $this->load->vars($data);
        
        $this->template->write_view('content', 'home/index');

        $this->template->render();
    }
    
// my master template looks like (code highlighting is broked, its not a parse error)

<body>
<ul id="nav">
<li class="home &lt;?php if($active=='home') echo 'active';?&gt;">
&lt;?=anchor(base_url(), 'Home');?&gt;
</li>
</ul>
&lt;!-- etc --&gt;


makes sense to me, but i'm clearly missing something. $active doesn't appear to be being set.

thanks !
#2

[eluser]WanWizard[/eluser]
That only works when you don't use a parser.

In that case, the template library calls $this->load->view() to load the template, and that supports $this->load->vars(). From a quick glance at the code, the Parser library doesn't.
For third party parsers, you could build it in. For example in case of Smarty, you could assign the content of $this->load->_ci_cached_vars using Smarty's assign method.
#3

[eluser]Ephyzy[/eluser]
Hi Met. I just found Williams Concepts Template 15 minutes ago, and I think it's awesome. Your code below
Code:
$this->load->vars($data);      
$this->template->write_view('content', 'home/index');
should rather read

Code:
$this->template->write_view('content', 'home/index', $data);

and everything will be fine.

Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB