Gallery2:Themes:Reference:Variables - Gallery Codex
Personal tools

Gallery2:Themes:Reference:Variables

From Gallery Codex

You can view all variables available on a particular page by turning on debug mode.

Some variables are made available in all themes / template files. Among these are:

  • isEmbedded -- True if site is viewed embedded in another application; false if viewed standalone.

User Information

Information about the active user:

  • $user.userName, $user.fullName, $user.email, ... all user attributes
  • $user.isGuest, $user.isRegisteredUser, $user.isAdmin which help to create page content that is only visible to logged in users (registeredUser) or admins, or guests.

Example code for G2 .tpl files:

 {if $user.isRegisteredUser}
 Welcome {$user.userName}!
 {else}
 Welcome, guest!
 {/if}

Item Information

  • $theme.item.id is the id (unique identifier) of the item shown in the current page. in photo.tpl, $theme.item.id is the id of the current data item (e.g. a photo)
  • Generally, you have access to all members of GalleryItem, e.g. $theme.item.canContainChildren is true for albums, false for photos and other data items.
  • $theme.item.title, $theme.item.summary, $theme.item.description are available as well. Don't forget to use the |markup modifier when using them.
  • Look at the smarty debug console to a list of all available variables.

Examples

Add comments link for the :

 {g->url arg1="view=comment.AddComment" arg2="itemId=`$theme.item.id`"}

Show comments link:

 {g->url arg1="view=comment.ShowComments" arg2="itemId=`$theme.item.id`"}

Page specific info

 {if $theme.pageType != 'admin'}
 this is seen on all pages except for the admin page.
 {/if}
 {if isset($controller) && ($controller == 'core.UserLogin')}
 login page only
 {/if}
  {if empty($theme.parents)}
  {if $theme.pageType != 'admin'}
  stuff on root album only and not a admin page
  {/if}
  {/if}
advertisements