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 !


Messages In This Thread
Williams Concepts Template + load->vars help - by El Forum - 10-11-2010, 03:11 PM
Williams Concepts Template + load->vars help - by El Forum - 10-11-2010, 04:27 PM
Williams Concepts Template + load->vars help - by El Forum - 10-12-2010, 02:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB