[SOLVED] showing content based on if logged in

astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Tue, 2005-04-05 23:57

I only want to display custom fields to logged in users.. others that are guests, that are not logged in.. will not see the custom filelds... how can this done on the template level?

like

          {if userloggedin}
          <h2 class="giTitle">Custom Field</h2>
          {/if}

I hope i am making myself somewhat understandable..

any help that can be given to me will be greatly appreciated...

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2005-04-06 14:58

we don't yet have a standard flag for logged-in or not, but for now you can change this in layouts/matrix/templates/albumBody.tpl and singleBody.tpl

    {if !empty($layout.itemDetailFiles)}
      {foreach from=$layout.itemDetailFiles key=moduleId item=detailFile}
        {include file="gallery:$detailFile" l10Domain="modules_$moduleId"}
      {/foreach}
    {/if}

to

    {if !empty($layout.itemDetailFiles)}
      {foreach from=$layout.itemDetailFiles key=moduleId item=detailFile}
{if $moduleId!='customfield' || $layout.user.id!=4}
        {include file="gallery:$detailFile" l10Domain="modules_$moduleId"}
{/if}
      {/foreach}
    {/if}
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-04-06 15:11

i guess this is a fairly popular request (having something like {g->isRegisteredUser}, or {g->isAdmin} don't you think?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2005-04-06 15:50

it needs to be something that can be used in {if} so maybe just standardize a template variable, like $user.isRegisteredUser or $user.isLoggedIn, and $user.isAdmin

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Fri, 2005-04-08 02:44

maybe we could create a module for this instead... at least for now.. i wouldnt really like to start changing source code around to get this to work more effiently on the template level.. and since we are in BETA.. i would like the files to be intact at least intill final release.. perhaps just writing out a function that we could call on any template page a member function where maybe we could get the users info like either they are logged in or not amongst other things.. would add more dynamic flare to this... we could force certain themes to be used by certain groups..

I really have not looked at the DB structure yet to see if this stuff is actually stored there or not.... or is it stored in flat file somehwere? I know G1 was totally flatfile.. so i really do not know how much G2 really leaned on the DB..

What I am also trying to do is.. instead of showing custom fields to logged in users.. i also only wanting to show the

$layout.item.description

description field as well.... I can see from the example above you are just looking at the url to know to show the custom field or not.. or am i wrong?

please help... thanks alot in advance :)

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-04-08 04:03

the url is not involved.. it is looking at the data used to build the page.
the changes i suggested above would be a local template and no code change is required.

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Fri, 2005-04-08 20:16
Quote:
What I am also trying to do is.. instead of showing custom fields to logged in users.. i also only wanting to show the

$layout.item.description

description field as well....

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-04-08 20:33

can't you apply the same technique?

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Fri, 2005-04-08 21:50

I guess if i really could understand the variable scope being used in these templates.. i wouldnt be asking these lame questions...

it seems to me that the above example checks to see if the custom field module is being used and then making sure the user is logged in.. then if both are true.. then the custom fields are shown... but can i really use the same technique for the description?

    {if !empty($layout.itemDetailFiles)}
    {foreach from=$layout.itemDetailFiles key=moduleId item=detailFile}

    {if $moduleId!='description' || $layout.user.id!=4}

    {include file="gallery:$detailFile" l10Domain="modules_$moduleId"}

    {/if}

    {/foreach}
    {/if}

please excuse my stupidity... :(

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Fri, 2005-04-08 22:07

so i went ahead and tried to do the first example.. it shows the custom field regardless if i am logged in or not..

hmmmm.....

if i cant get this to work.. then i cant really build on the original example to get the description to work the way that I want it to...

I am trying to get the desciption to only show if the user is logged in....

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-04-08 22:07

itemDetailFiles are additional content added by modules.. comments, custom fields, exif all use item detail content to display stuff below the album/image.
description isn't part of the itemDetailFiles loop.. look elsewhere in the tpl for where description is displayed.. you can put {if $layout.user.id!=4} .... {/if} around anything you want only shown to logged in users.

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Fri, 2005-04-08 22:08

ok.. will do.. i will try this right away mindless... i really appreciate your tireless effort here.. :)

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Fri, 2005-04-08 22:20

ok.. using the below example has no effect on showing description info to user logged in or not..


{if $layout.user.id!=4}

    {if !empty($layout.item.description)}

            <p class="giDescription">
              {$layout.item.description|markup}
            </p>     
 
    {/if}

{/if}

what gives?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-04-08 23:40

just above that {if put this:
{$layout.user.id}

this should put the id of the current user someone on the page.. see what value it has when you're logged in and not logged in.. we're expecting it to be 4 when you're not logged in.

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Sat, 2005-04-09 02:41

ok... {$layout.user.id} does in fact equal 4... but still.... no luck...

admin equals 5

but for some strange reason we cant use the {if} conditional to choose wether or not to display the information field.. or really.. anything for that matter... becasue it doesnt work for custom field either...

Maybe It would help to say that I only have two users..

admin

and

guest

I also have only 3 groups.. and those are

All Users
Everybody
Site Admins

I also would like to know what is in the $layout[user] array.. would group id be in there.. it would be much easier to do than member id...

 
astralbaby

Joined: 2003-12-13
Posts: 35
Posted: Sat, 2005-04-09 02:59

wow.. works a charm... i really feel like a dumb ace becasue i was working with thw wrong instance of where the description is called..

everything is working just fine.. I am so terribly sorry for my mistake.. and really would like to thank you for the time and help mindless...

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2005-04-09 03:50

:D

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-04-19 18:37

I have made a standard template variable so user info is available to every view. You can reference these in any tpl: $user.userName, $user.fullName, $user.isGuest, $user.isRegisteredUser, $user.isAdmin
Update from cvs in a few hours or get tomorrow's nightly snapshot to try this out. If you have any references to $layout.user in your local tpl files you'll need to change these to just $user.