You're not currently signed in.

Accessing data inside templates

As the Jifty class is instantiated as a singleton, all relevant things can get accessed by using the construct Jifty->anything, where 'anything' is one of the accessors of the Jifty class. The following accessors are possible:

  • Jifty->config gets the configuration object. It stores all the entries that are initially read (or, on absence of essential parameters, guessed) from the config file etc/config.yml.
  • Jifty->logger accesses the logger. The Jifty::Logger is a subclass of Log::Log4perl and provides the same methods (debug, info, warn, error and fatal). Alternatively, with every object, that is a descendent of Jifty::Object, you might directly use the log accessor of this very object to obtain a reference to the logger.
  • Jifty->handler gets the Mason handler object, see Jifty::Handler about things on which this might be useful. Usually there should be no need for directly interfering with this handler.
  • Jifty->handle retrieves the database Handle. As Jifty provides very powerful ways to interact with a data storage using models and collections there should usually be no need to directly access this object.
  • Jifty->web accesses the Web Object giving you very powerful control of all the features Jifty provides.
  • Jifty->api returns the Jifty::API object that manages access or restrictions to certain methods of actions.
  • Jifty->plugins returns an array of all installed plugins. Every entry of the array is an instantiated Jifty::Plugin module.

The two most powerful of all those accessors are config and web which are explained in more detail.

The Config Object

The config object reflects the current configuration, either read in from config.yml or guessed. The config object provides these two interesting accessors:

  • Jifty->config->framework('variable_name') gets the content of variablename_ of the of the framework configuration or undef if variablename_ does not exist.
    If some complex data structure resides under this key, the result value is a reference to this structure. So, deeper values might be obtained by calls like Jifty->config->framework('Web')->{'StaticRoot'}
  • Jifty->config->app('variable_name') gets the content of application variable _variable_name_ or undef if this key does not have any entry.

The Web Object

The web object is the work-horse and probably the most used object during your Jifty career. Here are some of the accessors grouped by their usage.

General:

  • Jifty->web->out('...') sends some string to the browser. This method could be useful to force some kind of text to appear at a given place from inside a perl section of a template, action or model. Please use this version against the mason output capabilities in favor of readable perl sequences that would lose their comprehensibility.
  • Jifty->web->url returns the root url of the Jifty application. Alternatively, Jifty->web->url(scheme=>'https') will return the root url for https: scheme. 'http' may also be used, but is the default if no arguments are given.
  • Jifty->web->session returns the session object allowing to set or get values that remain across multiple page requests for the same user.
  • Jifty->web->current_user sets or returns the current user object, which is an object of type ApplicationName::CurrentUser which has Jifty::CurrentUser as a base.

Request processing:

  • Jifty->web->request gets or sets the current Jifty::Request object. The request object already has some knowledge of Jifty's ability to work with continuations, actions and fragments for handing AJAX specific things.
  • Jifty->web->response gets or sets the current Jifty::Response object. A response is the answer to a request and collects all results of every single action invoked during the request processing.
  • Jifty->web->new_action(class=>'ClassName' [, ... ]) create and instantiate a new action object with the given class for the current template and add it to the current web object. Usually this step is done in the <%init> sestion of a template.
  • Jifty->web->failed_actions returns an array of action objects that failed.
  • Jifty->web->succeeded_actions returns an array of action objects that succeded.

Forms and Jumps:

  • Jifty->web->form returns the current Jifty::Web::Form object. If no object exists, a new object is created.
  • Jifty->web->next_page gets or sets the next page (an url) to show.
  • Jifty->web->redirect_required - used internally -
  • Jifty->web->redirect('/url/to/redirect/to.html') immediately redirects to the given url.
  • Jifty->web->caller returns the Jifty::Request object of your enclosing continuation or undef if you are not in a continuation.
  • Jifty->web->tangent(url=>'/jump/page.html' [, ... ]) produces and renders a Jifty::Web::Form::Clickable object that jumps to the given page allowing a return at the current page.
  • Jifty->web->goto(url=>'/jump/page.html' [, ... ]) forces an immediate jump to the target url.
  • Jifty->web->link(url=>'/jump/page.html' [, ... ]) Allows jumping to the given url by clicking on the link.
  • Jifty->web->return(to=>'/jump/page.html' [, ... ]) produces and renders a link that allows return to the current continuation or to the provided to URL if there is no current continuation.
  • Jifty->web->render_messages(...) renders all messages that have get collected during the validation process of all actions on the current template. If a moniker is given as a parameter, only messages for that moniker are rendered. The messages are rendered as two blocks, listing the error messages and then the success messages. Internally, the methods render_error_messages() and render_success_messages() are called with the optionally given moniker parameter.

Navigation:

  • Jifty->web->navigation returns the automatically generated object representing top navigation bar as a Jifty::Web::Menu object for this request.
  • Jifty->web->page_navigation returns the page navigation (a navigation bar that is rendered under control of your template) as a Jifty::Web::Menu object for this request.

State Variables:

  • Jifty->web->get_variable('varname') retrieve the value of a state variable that we got from the last request.
  • Jifty->web->set_variable('varname', some_value) set a value to get transported to the next request. This happens for every form rendered on the page after this call has been made and for every link that is marked as to preserve the state.
  • Jifty->web->state_variables used internally. Gets back an internal representation of all state variables that have been set for transporting to the next request.
  • Jifty->web->clear_state_variables clear all state variables.

Page regions:

  • Jifty->web->get_region('qualified_name') gives back a Jifty::Web::PageRegion object if an object with such a name exists, or undef otherwise.
  • Jifty->web->region(...) constructs a Jifty::Web::PageRegion from a given paramhash and renders the region into the generated HTML output.
  • Jifty->web->current_region returns the current Jifty::Web::PageRegion or undef if there is no region.
  • Jifty->web->qualified_region returns the fully qualified name of the current Jifty::Web::PageRegion or an empty string if no region exists. If a region object is supplied as a parameter, it's fully qualified name is returned.

Utility functions:

  • Jifty->web->query_string(key => value ...) This helper routine produces an URL-encoded query string that contains all given key/value pairs. Separate entries are separated by a semicolon.
  • Jifty->web->escape(...) returns a HTML-escaped string from its input.
  • Jifty->web->escape_uri returns an URI-escaped string from its input
  • Jifty->web->include_css includes all css definitions into the current generated HTML output.
  • Jifty->web->generate_css is used internally, generates all necessary css definitions.
  • Jifty->web->include_javascript includes all Javascript definitions into the current generated HTML output.
  • Jifty->web->generate_javascript is used internally, generates all necessary !JavaScript definitions.