Menu

Global variable or alt. idea for session var

gidon wise
2000-10-07
2000-10-08
  • gidon wise

    gidon wise - 2000-10-07

    Hello,

    First, thanks for html::template it's great.

    I have a large system up and running.
    And now all of a sudden I have to add some
    session info to all of the URL's.

    The problem is that the URL's are all in many different loops.

    And as you know, each Loop has a scope that is independent
    of everything else. So, I would have to put
    this session info into every iteration of every loop in all of my systems.

    This is a big ugly job.

    Is there an easier way?

    I thought of TMPL_INCLUDE because that works globally
    even in loops. But that's no good because I use
    cache and the session variables have to change
    between different usages.

    Anyone have any other ideas?

    How about a new GLOBAL variable?

    Thanks for your suggestions!

    Gidon

     
    • gidon wise

      gidon wise - 2000-10-08

      I couldn't wait, so I made a preliminary global patch.

      Here's how it works.

      Any variable that is defined in the main section.
      (In the section outside of any loop, get's put
      in the $HTML::Template::GLOBAL_pstack{$name} )

      When the code is in a loop and is looking for a variable,
      then it first checks the loop namespace, and then afterwards
      if there is no such variable, it checks the GLOBAL_pstack
      for the variable.

      I'm sure that everyone will be able to figure out how to
      make this better and easier to use.

      Issues include:
      1) You have to use (declare) the global somewhere
      in the html page.
            a. Maybe a variable prefix (e.g. name=GLOBAL_x) or different tag TMPL_GLOBAL would solve this problem.
      2) Anything that is in the main could be a global.
            a. solved by 1.a.

      Here is the diff:
      1413c1413,1417
      <           } else {
      ---
      >           } elsif (exists $HTML::Template::GLOBAL_pmap{$name}){
      >         $var = $HTML::Template::GLOBAL_pmap{$name};
      >             (ref($var) eq 'HTML::Template::VAR') or
      >               die "HTML::Template->new() : Already used param name $name as a TMPL_LOOP, found in a TMPL_VAR at $fname : line $fcounter.";
      >       }else{
      1415a1420
      >         $HTML::Template::GLOBAL_pmap{$name} = $var if ! @loopstack;

       
    • Sam Tregar

      Sam Tregar - 2000-10-08

      If you're using a recent version of HTML::Template, and you should be, you can use the 'global_vars' option.  It makes all variables available at all scopes and allows for pretty much exactly what you're looking for. 

      Good luck!
      -sam

       
      • gidon wise

        gidon wise - 2000-10-08

        Thanks!

        I guess I should have upgraded again before
        I posted the question and patch :)

        Gidon

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.