Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] How to pre-include a module *before* compiling a template?

Expand Messages
  • Tracy S. Ruggles
    I m creating a template manager class to use with webware and I am trying to figure out how to add something to the templates search list before it s compiled.
    Message 1 of 2 , Nov 3, 2003
    • 0 Attachment
      I'm creating a template manager class to use with webware and I am
      trying to figure out how to add something to the templates search list
      before it's compiled.

      Here's a snippet of the template manager's compile method:

      > def compile(self, name):
      > filepath = self.modToFilePath(name) # get long path
      > source = open('%s.tmpl' % filepath, 'r').read()
      > t = Template(searchList=[{'templates':self.package}])
      > t.compile(source=source, moduleName=name)
      > f = open('%s.py' % filepath, 'w')
      > f.write(t.generatedModuleCode())
      > f.close()

      I want the template source to have access to the package the template
      manager is compiling the templates into so that I can have something
      like this in template 'one':

      > #extends templates.master
      >
      > #block pageBody
      > <p>This is the page body.</p>
      > #end block

      And, then have a master.tmpl in the same directory:

      > <html>
      > <body>
      > #block pageBody
      > <!-- page body to be customized... -->
      > #end block
      > </body>
      > </html>

      What I need to do to successfully compile it is to have the
      'templatemgr' keyword be part of the searchlist and be defined as the
      python package the template manager works from. In the compile method
      above, I thought I'd be able to do something like this:

      > def compile(name):
      > ...
      > t = Template(_globalSetVars={'templates':self.package})
      > t.compile(source=source, moduleName=name)
      > ...

      ...where 'self.package' returns the relevant python package.

      Is there a way to get a package into the searchlist so that #extends
      <templatename> works in this dynamic mode?

      Thanks,
      Tracy

      P.S. I hope I'm making sense here. I can forward all the code of my
      template manager class if it would help.



      -------------------------------------------------------
      This SF.net email is sponsored by: SF.net Giveback Program.
      Does SourceForge.net help you be more productive? Does it
      help you create better code? SHARE THE LOVE, and help us help
      YOU! Click Here: http://sourceforge.net/donate/
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Tracy S. Ruggles
      I m creating a template manager class to use with webware and I am trying to figure out how to add something to the templates search list before it s compiled.
      Message 2 of 2 , Nov 3, 2003
      • 0 Attachment
        I'm creating a template manager class to use with webware and I am
        trying to figure out how to add something to the templates search list
        before it's compiled.

        Here's a snippet of the template manager's compile method:

        > def compile(self, name):
        > filepath = self.modToFilePath(name) # get long path
        > source = open('%s.tmpl' % filepath, 'r').read()
        > t = Template(searchList=[{'templates':self.package}])
        > t.compile(source=source, moduleName=name)
        > f = open('%s.py' % filepath, 'w')
        > f.write(t.generatedModuleCode())
        > f.close()

        I want the template source to have access to the package the template
        manager is compiling the templates into so that I can have something
        like this in template 'one':

        > #extends templates.master
        >
        > #block pageBody
        > <p>This is the page body.</p>
        > #end block

        And, then have a master.tmpl in the same directory:

        > <html>
        > <body>
        > #block pageBody
        > <!-- page body to be customized... -->
        > #end block
        > </body>
        > </html>

        What I need to do to successfully compile it is to have the
        'templatemgr' keyword be part of the searchlist and be defined as the
        python package the template manager works from. In the compile method
        above, I thought I'd be able to do something like this:

        > def compile(name):
        > ...
        > t = Template(_globalSetVars={'templates':self.package})
        > t.compile(source=source, moduleName=name)
        > ...

        ...where 'self.package' returns the relevant python package.

        Is there a way to get a package into the searchlist so that #extends
        <templatename> works in this dynamic mode?

        Thanks,
        Tracy

        P.S. I hope I'm making sense here. I can forward all the code of my
        template manager class if it would help.



        -------------------------------------------------------
        This SF.net email is sponsored by: SF.net Giveback Program.
        Does SourceForge.net help you be more productive? Does it
        help you create better code? SHARE THE LOVE, and help us help
        YOU! Click Here: http://sourceforge.net/donate/
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      Your message has been successfully submitted and would be delivered to recipients shortly.