A simpler method for what you're trying to accomplish:

public function action_init() {
  $this->add_template('blog', dirname(__FILE__).'/blog.php');
  $this->add_rule('"blog"','display_blog');
}

public function theme_route_display_blog( $theme, $url_params ) {
  $theme->display('blog');
}

This is new in 0.9.1 and very handy. It circumvents the whole "action_handler" system, so you'll be required to put all of your own variables into the theme (doesn't sound like it'll be a problem for your use), but it will directly output some template for a specific request.

If you're ambitious, you could even do this, which does the same thing:

public function action_init() {
  $this->add_template('blog', dirname(__FILE__).'/blog.php');
  $this->add_rule(
    '"blog"',
    'display_blog',
    function ( $theme, $url_params ) {
      $theme->display('blog');
    }
  );
}

Hope that helps.

Owen


On 4/28/2013 8:21 AM, Nathan Thomas wrote:
Hi all,

I've really enjoyed using Habari over the past couple of years, and the
transparency of the code has encouraged me to try to get to grips with
it a little more.

At the moment I'm trying to figure out how to display a custom template
when I click on a link. I managed to create the new template using
add_template, and it shows up when I call $theme->display('<new
template>'). However, when I tried to create a rewrite rule to display
the template whenever a specific URL is requested, I couldn't get it to
work.

Here's the code:

<code>
public function action_init() {
  $this->add_template('blog', dirname(__FILE__).'/blog.php',false);
         $this->add_rule('"blog"','display_blog');
     }

     public function action_handler_display_blog( $handler )
     {
         $handler->$theme->display('blog');
     }
</code>

 From what I understand, this should add a new rule that uses the
display_blog handler to display the blog.php template for the URL
'<siteurl>/blog', but I just get a 404.

Where am I going wrong?

Thanks,
Nathan

P.S. The new Habari site design looks great BTW!

--
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/habari-dev
---
You received this message because you are subscribed to the Google
Groups "habari-dev" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.



--
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/habari-dev
--- You received this message because you are subscribed to the Google Groups "habari-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to