Welcome Guest, Not a member yet? Register   Sign In
Template Parser Help

I'm fairly new to CI, but loving it so far. Currently, I'm working on a social networking app, and getting stuck on the profile wall for the users. I've got it setup so that it works much like Virb.com, where a default layout file exists that is simply an html file with tokens for the Template Parser to represent the different sections of the profile (like 'About', 'Groups', etc.)

I have it working where it scans the layout file for tokens used, then returns the array needed to pass into the Template parser. Works great. The problem I'm having, though, is when I try to pass data into the view for the token. For example, I have an 'about' view that formats the about section of the profile. Before I scan the file for tokens used, I grab the user profile information from the db, and pass that to the view through a switch for all of the available profile blocks. Like this:

In the Model:
function getLayoutTokens($id) {
  // Get the contents of our layout file
  $layout = getUserLayout($id);
  // Search for any tokens to be replaced.
  if ( preg_match_all('/\{[a-zA-Z_]*\}/', $layout,  $tokens) ) {
// Connect to the database
$user = getUser();

// We have some tokens, so go about replacing them.
foreach($tokens[0] as $token) {
   // Strip the brackets
   switch($token) {
  case '{meta}':
    $data['meta'] = $this->load->view('profile_blocks/meta', $user, TRUE);
  case "{groups}":
    $data['groups'] = $this->load->view('profile_blocks/groups', $user, TRUE);
  case "{about}":
    $data['about'] = $this->load->view('profile_blocks/about', $user, TRUE);
  // Make sure data exists before returning the values
  if (isset($data)) {
return $data;
  } else {
return NULL;

However, it doesn't seem to actually parse the information here, since I don't have access to the $user object, or any of it's contents, like $about. When it does get parsed through the Template Parser, it recognizes the $data passed there.

In the Controller:
function index() {
  // Get the user id to display
  $id = $this->uri->segment(2,0);
  // Load our user Styles
  $template['user_styles'] = getUserStyleLink($id);
  // Grab our user information
  $user = getUser($id);
  // Prep our parsing routine
  $layout = getUserLayoutLink($id);
  $data = $this->users_model->getLayoutTokens($id);
  $template['content'] = $this->parser->parse($layout, $data);

  // Then build and display our view.

Can anyone recommend a good solution? The only thing I can think of right now is load the user and add it to the $data in the Contstructor, but I was thinking the view would actually be parsed in the Model.

Theme © iAndrew 2016 - Forum software by © MyBB