Scope of $current_user variable

Author Message

James Ward

Thursday 08 December 2005 11:49:25 am

I have 2 pieces of code on the same page which use the $current_user variable.

In top.tpl (at the top of the page) I check to see if a user is logged in with the following code:

{if eq($current_user.contentobject_id,$anonymous_user_id)}

This check always behaves correctly and if I output the two id's I can see they are correct.

Further down on the same page, included in another file I do a similar check in product.tpl. However this check always fails and if I output the ids they have no value.

I tried adding # in front of the variable names in case of a scope issue. There is no mention of when these variables will NOT be available on the doc page:
http://ez.no/doc/ez_publish/technical_manual/3_6/templates/the_pagelayout/variables_in_pagelayout

Any thoughts on why these variables cease to exist?

working at www.wardnet.com
blogging at www.jamesward.ca

Ɓukasz Serwatka

Monday 12 December 2005 12:02:34 am

Hi James,

This variables are available only in pagelayout.tpl. What you can do in product.tpl is fetch current user and compare it with variable AnonymousUserID from site.ini for example:

{def $current_user=fetch( user, current_user )}

{if eq( $current_user.contentobject.id, 
                 ezini( 'UserSettings', 'AnonymousUserID', 'site.ini' ) )}
.
.
.

 

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 22 2025 01:58:53
Script start
Timing: Jan 22 2025 01:58:53
Module start 'layout'
Timing: Jan 22 2025 01:58:53
Module start 'content'
Timing: Jan 22 2025 01:58:53
Module end 'content'
Timing: Jan 22 2025 01:58:53
Script end

Main resources:

Total runtime0.0199 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0074 592.7891151.2109
Module start 'layout' 0.00740.0039 744.000036.6641
Module start 'content' 0.01130.0067 780.664190.2656
Module end 'content' 0.01800.0018 870.929729.9922
Script end 0.0198  900.9219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002613.1783140.0002
Check MTime0.00125.8885140.0001
Mysql Total
Database connection0.00073.402610.0007
Mysqli_queries0.005125.478430.0017
Looping result0.00000.086410.0000
Template Total0.00136.710.0013
Template load0.00105.042710.0010
Template processing0.00031.635310.0003
Override
Cache load0.00073.321010.0007
General
dbfile0.00157.467480.0002
String conversion0.00000.151240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs