Search the web
Sign In
New User? Sign Up
mt-dev · Movable Type Developers
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
How should I initialize a template context?   Message List  
Reply | Forward Message #2092 of 2112 |
Re: [mt-dev] How should I initialize a template context?

If you already have a template object (from the db) loaded, you can do:

my $ctx = $tmpl->context;

The error is because your context does not include a blog context --
it can't find $blog->server_offset because the blog is undefined. I
believe that using the method above will inherit the blog context of
the template in question, this avoiding this error.

-Mark

On Tue, Sep 2, 2008 at 5:25 PM, Michael Thomsen <mikerthomsen@...> wrote:
> I have a template file in a plugin that I need to compile and write
> the HTML to a separate directory. I've seen the following way to
> initialize a MT::Template::Context object to pass to
> MT::Template->build, but it causes an error. This is use in the docs:
>
> my $ctx = MT::Template::Context->new();
>
> Yet when I run that in a callback method attached to MT::Comment, I
> get the following error in my error log:
>
> died with: Can't call method "server_offset" on an undefined value at
> lib/MT/Template/ContextHandlers.pm line 10075.
>
> All I need to do is load the template, build it to HTML, and write it
> to a file. How should I setup the Context so that I can do this?
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>



Wed Sep 3, 2008 12:17 pm

bsakamano
Offline Offline
Send Email Send Email

Forward
Message #2092 of 2112 |
Expand Messages Author Sort by Date

I have a template file in a plugin that I need to compile and write the HTML to a separate directory. I've seen the following way to initialize a...
Michael Thomsen
codemonkeyov...
Offline Send Email
Sep 2, 2008
8:25 pm

What version are you working with? Sent from my iPhone On Sep 2, 2008, at 16:25, "Michael Thomsen" <mikerthomsen@...>...
Timothy Appnel
tappnel
Offline Send Email
Sep 2, 2008
10:28 pm

4.21 Pro...
Michael Thomsen
codemonkeyov...
Offline Send Email
Sep 2, 2008
11:46 pm

If you already have a template object (from the db) loaded, you can do: my $ctx = $tmpl->context; The error is because your context does not include a blog...
Mark Carey
bsakamano
Offline Send Email
Sep 3, 2008
12:17 pm

Hmmm, see I'm loading the template from a plugin directory, not the database. Do I need to register the tmpl file in the registry to make this easier?...
Michael Thomsen
codemonkeyov...
Offline Send Email
Sep 3, 2008
12:40 pm

... In that case, you were probably on the right track originally, but you need add the blog context manually: my $ctx = MT::Template::Context->new(); ...
Mark Carey
bsakamano
Offline Send Email
Sep 3, 2008
5:31 pm

Ok, that works. How do I pass it variable values so that tags like <mt:var and <mt:loop can get populated? What I have right now is: $params{items} =...
Michael Thomsen
codemonkeyov...
Offline Send Email
Sep 3, 2008
5:54 pm

Michael, you should be able to just shove any other variables you want into the $params hash you have setup there. I'm not real great with my perl and what...
jesse
jessedp23
Offline Send Email
Sep 3, 2008
6:04 pm

Thanks, but that doesn't seem to work with MT::Template->build. I was logging the output, and each time it kept ignoring the params hash....
Michael Thomsen
codemonkeyov...
Offline Send Email
Sep 3, 2008
6:12 pm

... While there is likely more than one way, here is one way to populate <mt:var>: $ctx->var( 'commenter_author_name', $name ); For <mt:loop, it seems like...
Mark Carey
bsakamano
Offline Send Email
Sep 4, 2008
3:28 pm

Yeah, that's the gist of what I was doing with the loop variable. It was just a list with a series of hashes inside of it. Thanks for the info!...
Michael Thomsen
codemonkeyov...
Offline Send Email
Sep 4, 2008
3:37 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help