Changeset 1312


Ignore:
Timestamp:
Mar 14, 2012, 5:14:30 PM (10 years ago)
Author:
kake
Message:

Made the 'username' TT variable accessible to all templates.

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r1311 r1312  
    55
    660.66    ?
     7        All templates now have access to the "username" TT variable.
    78        Add CSS classes for each category and locale to the "content" div
    89          (and hence we now require version 2.24 of Template).
  • trunk/MANIFEST

    r1311 r1312  
    156156t/86_recent_changes.t
    157157t/90_css_category_locale_classes.t
     158t/91_username_in_templates.t
    158159t/templates/15_test.tt
    159160wiki.cgi
  • trunk/lib/OpenGuides/Template.pm

    r1308 r1312  
    191191    }
    192192
    193     # Now set further TT variables if explicitly supplied - do this last
    194     # as these override auto-set ones.
     193    # Now set further TT variables if explicitly supplied - do this after the
     194    # above auto-setting as these override auto-set ones.
    195195    $tt_vars = { %$tt_vars, %{ $args{vars} || {} } };
     196
     197    # Finally, dig out the username from the cookie if we haven't already
     198    # been sent it in vars.
     199    if ( !$tt_vars->{username} ) {
     200        my %prefs = OpenGuides::CGI->get_prefs_from_cookie(config => $config);
     201        # If there's nothing in there, it defaults to "Anonymous".
     202        if ( $prefs{username} ne "Anonymous" ) {
     203          $tt_vars->{username} = $prefs{username};
     204        }
     205    }
    196206
    197207    my $header = "";
  • trunk/preferences.cgi

    r1236 r1312  
    3939        push @cookies, $rc_cookie;
    4040    }
     41    # We have to send the username to OpenGuides::Template because they might
     42    # have changed it, in which case it won't be in the cookie yet.
    4143    print OpenGuides::Template->output(
    4244        wiki     => $wiki,
     
    4749                      not_editable => 1,
    4850                      not_deletable => 1,
     51                      username => $prefs{username},
    4952                    }
    5053    );
Note: See TracChangeset for help on using the changeset viewer.