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


From Gallery Codex

Gallery2 Smarty Objects

Gallery extends Smarty by adding the g object which gives access to several Gallery functions. The g object's methods are described below, and can be accessed from a template by using the object syntax:

{g->method param1="value" ... paramN="value"}

where param1...paramN are the parameters that the method takes. The code implementing these methods is in modules/core/classes/GalleryTemplateAdapter.class.

g Object Methods


Usage: {g->block type=blockType [block-specific parameters]}

  • g->block inserts a Gallery block in a template. This is similar to the blocks that are configured for albums, photos, etc through the Site Admin interface
  • Gallery2 Blocks lists the available blocks along with their parameters
  • Examples of g->block in use can be found in the source code of the templates that come with Gallery, for example in the Floatrix theme


Usage: {g->container type='containerType' [container-specific parameters]} ... {/g->container}

  • g->container inserts a container in a template, for example an image frame
  • g->container requires a closing tag /g->container
  • Content between the opening and closing g->container tags is included within the container


Usage: {g->callback type=callbackType [callback-specific parameters]}

  • Callbacks are used by blocks to load data for the block. g->callback starts a callback
  • Gallery2 Callbacks lists the callbacks implemented in Gallery2 along with their parameters


Usage: {g->url href=hrefUrl params=array arg1="param=value" arg2="param=value" htmlEntities=false forceDirect=true forceFullUrl=true forceSessionId=true|false

  • htmlEntities=false replaces & with & in the url (previously was forJavascript=true)
  • forceDirect=true to generate a G2 site url even if embedded
  • forceFullUrl=true to generate an absolute url rather than a relative path url
  • forceSessionId=true/false to specify if the G2 session id should be embedded in the url; by default it is included only for non-href urls when cookies are not in use
  • params= and arg#= can be used together starting in G2.2 (arg1,etc added to given params array)


g->image [item=..] [image=..] [maxSize=..] [fallback=..] [other params for <img>]

  • Render html content for selected item; usually <img> but can be embedded movie, etc.


g->date [timestamp=..] [format=..] [style=..]

  • Default timestamp is current date/time
  • Use given format if specified; otherwise use system setting for given style (date, time or datetime; default is date)
  • See strftime docs for valid tokens in format string


g->text [text=..] [arg1=.. arg2=...] [l10Domain=..] [forJavascript=true] [hint=..] [cFormat=..] [postSprintfArg1=..]

  • Using this tag marks text for translation
  • Default l10Domain is currently selected theme or module
  • forJavascript replaces any ' characters with \'
  • arg1, arg2, etc are used when text=.. contains printf-style tokens like %s or %d
  • Alternate parameters: one=.. many=.. count=.. [arg1=.. etc]
    If count is one then use one=.. string, otherwise use many=.. string
  • hint=".." provides text placed in po files to assist translators (must use double quotes, not single)
  • cFormat=false ensures PO files for translation don't interpret this text as c-format even if it contains a % character
  • postSprintfArg1=".." attempts specific translation of string after sprintf with this value; if no translation found, falls back to normal translation of string with %s in it, doing sprintf afterwards. Example:
 {g->text text="%s Date and Time" arg=$ItemEditItem.typeName.0 postSprintfArg1=$ItemEditItem.typeName.2}
 {* Specific translations: {g->text text="Link Date and Time"} *}


g->theme [include=..] or [url=..]

  • Include is a shortcut for {include file="gallery:[path to theme/templates]/.."}
  • Url is a shortcut for {g->url href="[path to theme]/.."}


g->formVar [var=..]

  • Add prefix on given variable name; example; var="form[input]" gives g2_form[input]


g->autoComplete [element=..]

  • Add autoComplete support to a form text element with the given id
    Put the url to generate the autoComplete list between {g->autoComplete}..{/g->autoComplete} with __VALUE__ token for the text typed so far (see example in modules/core/templates/AdminCore.tpl)


g->dimensions [formVar=..] [width=..] [height=..]

  • Add form elements for entering dimensions
    Javascript autofills the second dimension with the same value as the first, unless the second is edited directly (see example in modules/core/templates/ItemEditPhoto.tpl)


g->defaultButton [name=..]

  • Add hidden form element to specify a default submit button that is used when enter is pressed in a text input
    Must appear before any other submit buttons in the form (see example in modules/core/templates/AdminEditGroupUsers.tpl)


g->changeInDescendents [module=..] [g->text params..]

  • Add a checkbox for the given module with the given text.
  • Used in ItemEdit forms by ItemEditOptions to add an option to apply changes recursively to subitems.


g->linkId [urlParams=..]

  • Generate a css classname for given link; classes used by icons module


g->itemLink link=.. [type=..] [lowercase=..] [..]

  • Render an item action as <a> link or <option> for select list.
  • link parameter is data loaded into template by 'itemLinks' key to loadCommonTemplateData.
  • Pass type="option" for an <option> tag (to build a <select> list); otherwise generates an <a>.
  • Pass lowercase=true to change the text for all actions to lowercase.
  • Any additional parameters will be added as attributes on the <a> or <option> tag.
  • Pass class=null to omit the CSS classes added by default on <a> links (for icons).
  • Example: {foreach from=$theme.itemLinks item=link}{g->itemLink link=$link lowercase=true}{/foreach}
  • Note: new in Gallery 2.3



  • Display prepared <head> content (title, css, javascript, meta)



  • Id and classes for main Gallery <div>



  • Language in format for HTML lang attribute


g->logoButton [type=..] [target=..] [link=false] [showToAll=true]

  • Type can be gallery2, gallery2-version, donate or validation
  • Optional target parameter adds link target (example: target="_blank")
  • Optional link=false to not have any link, just show the logo
  • Optional showToAll=true to always show logo (by default all types except "gallery2" are shown only to site admins)
  • (link/showToAll parameters added in CVS after release of Gallery 2.1)



  • Add {g->hiddenFormVars} to all your <form> blocks in your templates. Otherwize your form will probably not work (missing controller variable, missing authToken, ...).



  • Put content to be added at end of page inside {g->addToTrailer}..{/g->addToTrailer}



  • Display content that was added to trailer



  • Display debug output if it was collected (see config.php)