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->configgets the configuration object. It stores all the entries that are initially read (or on absence of essential parameters guessed) from the config fileetc/config.yml.Jifty->loggeraccesses the logger. TheJifty::Loggeris a subclass ofLog::Log4perland provides the same methods (debug,info,warn,errorandfatal). Alternatively, with every object, that is a descendent ofJifty::Object, you might directly use thelogaccessor of this very object to obtain a reference to the logger.Jifty->handlergets the Mason handler object, seeJifty::Handlerabout things on which this might be useful. Usually there should be no need to directly interfering with this handler.Jifty->handleretrieves 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->webaccesses the Web Object giving you very powerful control of all the features, Jifty provides.Jifty->apireturns theJifty::APIobject that manages access or restrictions to certain methods of actions.Jifty->pluginsreturns an array of all installed plugins. Every entry of the array is an instantiated Jifty::Plugin module.
The most two powerful of all those accessors are config and web which are explained in more detail.
The Config Object
As the config object reflects the current configuration read in from config.yml or guessed. The config object provides these two interesting accessors:
Jifty->config->framework('variable_name')get the content of variablename_ of the of the framework configuration orundefif variablename_ does not exist.
If under this key resides some complex data structure, the result value is a reference to this structure. So, deeper values might be obtained by calls likeJifty->config->framework('Web')->{'StaticRoot'}Jifty->config->app('variable_name')get the content of application variable_variable_name_orundefif this key does not have any entry.
The Web Object
The web object is the working 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('...')send 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 agains the mason output capabilities in favor of readable perl sequences that would loose their comprehensibility.Jifty->web->urlreturns 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->sessionreturns the session object allowing to set or get values that remain across multiple page requests for the same user.Jifty->web->current_usersets or returns the current user object, which is an object of typeApplicationName::CurrentUserwhich hasJifty::CurrentUseras a base.
Request processing:
Jifty->web->requestgets or sets the currentJifty::Requestobject. 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->responsegets or sets the currentJifty::Responseobject. 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_actionsreturns an array of action objects that failed.Jifty->web->succeeded_actionsreturns an array of action objects that succeded.
Forms and Jumps:
Jifty->web->formreturns the currentJifty::Web::Formobject. If no object exists, a new object is created.Jifty->web->next_pagegets 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->callerreturns theJifty::Requestobject of your enclosing continuation orundefif you are not in a continuation.Jifty->web->tangent(url=>'/jump/page.html' [, ... ])produces and renders aJifty::Web::Form::Clickableobject 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 providedtoURL 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 methodsrender_error_messages()andrender_success_messages()are called with the optionally given moniker parameter.
Navigation:
Jifty->web->navigationreturns the automatically generated object representing top navigation bar as aJifty::Web::Menuobject for this request.Jifty->web->page_navigationreturns the page navigation (a navigation bar that is rendered under control of your template) as aJifty::Web::Menuobject 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_variablesused internally. Gets back an internal representation of all state variables that have been set for transporting to the next request.Jifty->web->clear_state_variablesclear all state variables.
Page regions:
Jifty->web->get_region('qualified_name')gives back aJifty::Web::PageRegionobject if an object with such a name exists, or undef otherwise.Jifty->web->region(...)constructs aJifty::Web::PageRegionfrom a given paramhash and renders the region into the generated HTML output.Jifty->web->current_regionreturns the currentJifty::Web::PageRegionor undef if there is no region.Jifty->web->qualified_regionreturns the fully qualified name of the currentJifty::Web::PageRegionor 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_urireturns an URI-escaped string from its inputJifty->web->include_cssincludes all css definitions into the current generated HTML output.Jifty->web->generate_cssis used internally, generates all necessary css definitions.Jifty->web->include_javascriptincludes all Javascript definitions into the current generated HTML output.Jifty->web->generate_javascriptis used internally, generates all necessary !JavaScript definitions.