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

Re: [Cheetahtemplate-discuss] #set global

Expand Messages
  • Johannes Erdfelt
    ... You can t do that. When you include another template, it ll have a different namespace. You can probably do what you want via inheritance tho. JE ... This
    Message 1 of 10 , Oct 1, 2002
    • 0 Attachment
      On Tue, Oct 01, 2002, Mike Warren <spam@...> wrote:
      > According to the documentation, I believe I should be able to do
      > something like this:
      >
      > ,----[first.tmpl]
      > | #set global $mike="mike warren"
      > | #include "another_template.tmpl"
      > `----
      >
      > ,----[another_template.tmpl]
      > | <title>$mike</title>
      > `----
      >
      > And get <title>mike warren</title> in my output. This doesn't work for
      > me, though; the included template throws exceptions complaining
      > ``mike'' isn't defined.
      >
      > This is with CVS Cheetah updated today (just now, actually).
      >
      > Any hints? Thanks,

      You can't do that. When you include another template, it'll have a
      different namespace.

      You can probably do what you want via inheritance tho.

      JE



      -------------------------------------------------------
      This sf.net email is sponsored by: DEDICATED SERVERS only $89!
      Linux or FreeBSD, FREE setup, FAST network. Get your own server
      today at http://www.ServePath.com/indexfm.htm
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Mike Warren
      ... Hash: SHA1 According to the documentation, I believe I should be able to do something like this: ,----[first.tmpl] ... `---- ,----[another_template.tmpl]
      Message 2 of 10 , Oct 1, 2002
      • 0 Attachment
        -----BEGIN PGP SIGNED MESSAGE-----
        Hash: SHA1


        According to the documentation, I believe I should be able to do
        something like this:

        ,----[first.tmpl]
        | #set global $mike="mike warren"
        | #include "another_template.tmpl"
        `----

        ,----[another_template.tmpl]
        | <title>$mike</title>
        `----

        And get <title>mike warren</title> in my output. This doesn't work for
        me, though; the included template throws exceptions complaining
        ``mike'' isn't defined.

        This is with CVS Cheetah updated today (just now, actually).

        Any hints? Thanks,

        - --
        mike@...
        <URL:http://www.mike-warren.com>
        gpg --keyserver 80.71.227.37 --recv-key 579911BD
        87F2 4D98 BDB0 0E90 EE2A 0CF9 1087 0884 5799 11BD


        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.0.7 (GNU/Linux)
        Comment: Processed by Mailcrypt 3.5.6 and Gnu Privacy Guard <http://www.gnupg.org/>

        iD8DBQE9mipoEIcIhFeZEb0RAiueAJ9CCgfSJ+yYqHoVrGse4fy87Zy62gCffGqN
        Q3sg4m7HKl+pIcEJJ6Mr9XM=
        =JO2F
        -----END PGP SIGNATURE-----


        -------------------------------------------------------
        This sf.net email is sponsored by: DEDICATED SERVERS only $89!
        Linux or FreeBSD, FREE setup, FAST network. Get your own server
        today at http://www.ServePath.com/indexfm.htm
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Mike Orr
        ... Hmm, it works for me. Can you run cheetah compile on both files and send me the *.tmpl and the *.py versions? Maybe that will yield a clue. You can also
        Message 3 of 10 , Oct 1, 2002
        • 0 Attachment
          On Tue, Oct 01, 2002 at 05:06:18PM -0600, Mike Warren wrote:
          > -----BEGIN PGP SIGNED MESSAGE-----
          > Hash: SHA1
          >
          >
          > According to the documentation, I believe I should be able to do
          > something like this:
          >
          > ,----[first.tmpl]
          > | #set global $mike="mike warren"
          > | #include "another_template.tmpl"
          > `----
          >
          > ,----[another_template.tmpl]
          > | <title>$mike</title>
          > `----
          >
          > And get <title>mike warren</title> in my output. This doesn't work for
          > me, though; the included template throws exceptions complaining
          > ``mike'' isn't defined.

          Hmm, it works for me.

          Can you run "cheetah compile" on both files and send me the *.tmpl and
          the *.py versions? Maybe that will yield a clue.

          You can also put $searchList in the template to see what the searchList
          contains. The first item should be the dictionary of globals (i.e., it
          should have a 'mike' key).

          --
          -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
          http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


          -------------------------------------------------------
          This sf.net email is sponsored by: DEDICATED SERVERS only $89!
          Linux or FreeBSD, FREE setup, FAST network. Get your own server
          today at http://www.ServePath.com/indexfm.htm
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Mike Warren
          ... I just get ``[{}, ] if I put ``$searchList in my included template. Attached is a boiled-down test
          Message 4 of 10 , Oct 1, 2002
          • 0 Attachment
            iron@... (Mike Orr) writes:

            > You can also put $searchList in the template to see what the searchList
            > contains. The first item should be the dictionary of globals (i.e., it
            > should have a 'mike' key).

            I just get ``[{}, <Cheetah.Parser.GenTemplate instance at
            0x844bbec>]'' if I put ``$searchList'' in my included
            template.

            Attached is a boiled-down test case from what I really ;) had...
          • Mike Orr
            ... Sure enough, the included file is not picking up the main searchList. I added $searchList in the main template and labels above each of them. I ll look at
            Message 5 of 10 , Oct 2, 2002
            • 0 Attachment
              On Tue, Oct 01, 2002 at 06:24:33PM -0600, Mike Warren wrote:
              > iron@... (Mike Orr) writes:
              >
              > > You can also put $searchList in the template to see what the searchList
              > > contains. The first item should be the dictionary of globals (i.e., it
              > > should have a 'mike' key).
              >
              > I just get ``[{}, <Cheetah.Parser.GenTemplate instance at
              > 0x844bbec>]'' if I put ``$searchList'' in my included
              > template.

              Sure enough, the included file is not picking up the main searchList.
              I added $searchList in the main template and labels above each of them.
              I'll look at it some more tonight. In the meantime, maybe Tavis will
              have some insight.

              Main searchList:
              [{'newswire': <MyClass.MyOtherClass instance at 0x8245afc>},
              <__main__.main instance at 0x81346d4>]

              <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
              <html>
              <head>
              </head>

              <body text="black" link="blue" vlink="blue" alink="#9999ff"
              leftmargin="0" marginheight="0" marginwidth="0"
              topmargin="0">

              <!-- head.tmpl -->

              Included searchList:
              [{}, <Cheetah.Parser.GenTemplate instance at 0x824ab94>]

              I think this is supposed to be identical to the main searchList, but
              the MyOtherClass instance is also missing, and the 'self' is different.

              --
              -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
              http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


              -------------------------------------------------------
              This sf.net email is sponsored by:ThinkGeek
              Welcome to geek heaven.
              http://thinkgeek.com/sf
              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            • Mike Orr
              ... But the included searchList is correct if you comment out #extends Base in the include file. Correct meaning it s identical to the main searchList. You
              Message 6 of 10 , Oct 2, 2002
              • 0 Attachment
                On Wed, Oct 02, 2002 at 09:37:53AM -0700, Mike Orr wrote:
                > On Tue, Oct 01, 2002 at 06:24:33PM -0600, Mike Warren wrote:
                > > iron@... (Mike Orr) writes:
                > >
                > > > You can also put $searchList in the template to see what the searchList
                > > > contains. The first item should be the dictionary of globals (i.e., it
                > > > should have a 'mike' key).
                > >
                > > I just get ``[{}, <Cheetah.Parser.GenTemplate instance at
                > > 0x844bbec>]'' if I put ``$searchList'' in my included
                > > template.
                >
                > Sure enough, the included file is not picking up the main searchList.

                But the included searchList is correct if you comment out
                #extends Base
                in the include file. "Correct" meaning it's identical to the main
                searchList. You may be getting hit by the "double-initialize" bug
                that has been observed with #extends in certain cases. The case
                we've found is when you give the Template constructor a string or
                file containing "#extends" (rather than filling a precompiled
                template, which works).

                Can you get by without Base features in the include file for now?

                Actually, I don't think you even have to do that. Since the main
                template inherits from MyClass, all its methods are available to
                placeholders in the included template too. Of course that means
                the include file won't work if the main template doesn't inherit
                from MyClass, but maybe that's an inappropriate use of the include
                template anyway.

                --
                -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
                http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


                -------------------------------------------------------
                This sf.net email is sponsored by:ThinkGeek
                Welcome to geek heaven.
                http://thinkgeek.com/sf
                _______________________________________________
                Cheetahtemplate-discuss mailing list
                Cheetahtemplate-discuss@...
                https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
              • Mike Orr
                Regarding Mike Warren s problem with an included template not seeing the main searchList, it seems to work now after the double-initialization bugfix Tavis
                Message 7 of 10 , Oct 5, 2002
                • 0 Attachment
                  Regarding Mike Warren's problem with an included template not
                  seeing the main searchList, it seems to work now after the
                  double-initialization bugfix Tavis checked into CVS today.

                  --
                  -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
                  http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


                  -------------------------------------------------------
                  This sf.net email is sponsored by:ThinkGeek
                  Welcome to geek heaven.
                  http://thinkgeek.com/sf
                  _______________________________________________
                  Cheetahtemplate-discuss mailing list
                  Cheetahtemplate-discuss@...
                  https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                • Mike Warren
                  ... Yes, thanks. ... I was half expecting #include to work like an #include does with the C preprocessor (before reading the docs ;); would it make sense to
                  Message 8 of 10 , Oct 7, 2002
                  • 0 Attachment
                    iron@... (Mike Orr) writes:

                    > Can you get by without Base features in the include file for now?

                    Yes, thanks.

                    > Actually, I don't think you even have to do that. Since the main
                    > template inherits from MyClass, all its methods are available to
                    > placeholders in the included template too. Of course that means the
                    > include file won't work if the main template doesn't inherit from
                    > MyClass, but maybe that's an inappropriate use of the include
                    > template anyway.

                    I was half expecting #include to work like an #include does with the C
                    preprocessor (before reading the docs ;); would it make sense to add
                    sematics to do that? (That is, include the text and presume it to be
                    part of the ``current'' file?) Maybe ``#include cpp "filename.tmpl"''?

                    --
                    mike [at] mike [dash] warren [dot] com
                    <URL:http://www.mike-warren.com>
                    gpg --keyserver 80.71.227.37 --recv-key 579911BD
                    87F2 4D98 BDB0 0E90 EE2A 0CF9 1087 0884 5799 11BD


                    -------------------------------------------------------
                    This sf.net email is sponsored by:ThinkGeek
                    Welcome to geek heaven.
                    http://thinkgeek.com/sf
                    _______________________________________________
                    Cheetahtemplate-discuss mailing list
                    Cheetahtemplate-discuss@...
                    https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                  • Tavis Rudd
                    Hi Mike, ... That s actually something that I purposefully left out and have no intention of adding. I can t speak for C, but in languages like PHP and PSP
                    Message 9 of 10 , Oct 11, 2002
                    • 0 Attachment
                      Hi Mike,
                      On October 7, 2002 03:54 pm, Mike Warren wrote:
                      > I was half expecting #include to work like an #include does with the C
                      > preprocessor (before reading the docs ;); would it make sense to add
                      > sematics to do that? (That is, include the text and presume it to be
                      > part of the ``current'' file?) Maybe ``#include cpp "filename.tmpl"''?

                      That's actually something that I purposefully left out and have no intention
                      of adding. I can't speak for C, but in languages like PHP and PSP heavy use
                      of that style of include is one of the worst systems of spaghetti code.

                      Cheetah's parsed #include's are a short-cut for the following semantics:
                      import a template from a file, share a searchList with it, fill it, and
                      include its output string. '#include raw' is a short-cut for the following
                      semantics: open a file, read its contents into a string, include the string.

                      I'm not totally happy with cheetah's parsed includes, but I've left them in
                      because other people find them useful. I find Python's module and import
                      semantics to be much cleaner and use them almost exclusively.

                      Cheers,
                      Tavis


                      -------------------------------------------------------
                      This sf.net email is sponsored by:ThinkGeek
                      Welcome to geek heaven.
                      http://thinkgeek.com/sf
                      _______________________________________________
                      Cheetahtemplate-discuss mailing list
                      Cheetahtemplate-discuss@...
                      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                    • Tavis Rudd
                      ... This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________
                      Message 10 of 10 , Oct 11, 2002
                      • 0 Attachment
                        On October 11, 2002 01:57 pm, Tavis Rudd wrote:
                        >
                        > That's actually something that I purposefully left out and have no
                        > intention of adding. I can't speak for C, but in languages like PHP and
                        > PSP heavy use of that style of include is one of the worst systems of
                        > spaghetti code.
                        ... one of the worst symptoms ...



                        -------------------------------------------------------
                        This sf.net email is sponsored by:ThinkGeek
                        Welcome to geek heaven.
                        http://thinkgeek.com/sf
                        _______________________________________________
                        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.