Jifty::View::Declare::Page::NewStyle - new style page wrapper to simplify customization and reuse.
This library is a replacement for Jifty::View::Declare::Page. That is in Jifty for a while and can not be replaced with something completely different because of backwards compatibility.
When you declare a Jifty::View::Declare template that is a page, for example:
template 'news' => page { ... };
Page classes come into game. First of all App::View::Page is loaded (it's not true and there is a way to define class for particular page, but lets leave it alone as interface is not settled enough to be discussed). If the app class doesn't exist then default Jifty::View::Declare::Page is used. Code block right after page token is used to render core of the page wrapped into some layout. Page classes implement such layouts.
It's very hard to extended Jifty::View::Declare::Page class as it's written in such a way that forces you to copy&paste some internals from the class to make overridden method work and don't break things.
I think this implementation is much better thing. To use this class as a base for all your pages you can just add this plugin to your app and simple YourApp::View::Page will be generated for you. However, if you're here then you want to change layout, your App::View::Page should be something like:
package MyApp::View::Page; use base qw(Jifty::Plugin::ViewDeclarePage::Page); use Jifty::View::Declare::Helpers; ... 1;
Yes, that's it. No call to show('/menu'), instead it's a method "render_navigation" here. Why? If it's subclassable then there is no need to split functionality between different modules. You can always return old behavior by using:
sub render_navigation { show(/menu) }
override "render_content".
Even when there is no 'page_title is ...' in the content code, see "instrument_content" and "render_title_inpage".
All HTML is just escaped. 99% of apps don't want to put tags inside title. Sure, it's wrapped into <h1> tag. See "render_title_inpage"
Can be used in the content code to define feeds, relative links and other cool stuff. See "instrument_content" and "render_link_inpage".
It's documented!
Code reference that renders the core of the page, this is code block right after page token in the following example:
Is set by jifty during construction of the page object.
A hash reference that is set by jifty during construction of the page object. It's empty unless you use the following syntax:
template my_page => page { some => 'value', ... } content { ... };
In this case _meta is a reference to the hash that goes right after page token and content_code is after content token.
These are internal temporary holders of corresponding data.
Sets up a new page class. Called by Jifty with content_code and optional _meta.
Calls "init" right before returning new instance of the class.
Sets _title accessor from 'title' in _meta if the latter is defined, so you can do the following if title of a page is static:
template news => page { title => _('News') } content { ... };
Renders whole page from doctype till closing html tag. Takes no arguments.
This method drives rendering of the page. Page is split into three major parts: header, body and footer. Each is implemented as corresponding method with 'render_' prefix.
It worth to note that order of rendering is changed and header is rendered after the body to allow you define page title, RSS feeds and other things in content. Read more about this below in "render_header" and "instrument_content".
Renders an HTML "doctype" and complete <head> tag. Usually you don't want to override this. This method is rendered after body and main content of the page, so all things you need in head tag you can define in content.
Calls "render_doctype".
page_title is ...
You can define dynamic title using the following:
template some => page { my $page_title = ...; ... page_title is $page_title; ... };
Don't want to define dynamic title then as well you can use syntax described in "init" above.
When 'page_title is' is used in the content code, "render_title_inpage" is called, read more in "instrument_content".
"render_title_inhead" is called during rendering of the head tag, so you can change title there as well by subclassing that method.
add rel ...
add rev ...
You can add <link> tags right from the content using the following syntax:
add rel "alternate", type => "application/atom+xml", title => _('Updated this week'), href => '/feeds/atom/recent', ;
When these constructions are used, "render_link_inpage" is called so you can add something right in the page content, for example RSS image with link to the feed. See also "instrument_content".
"render_links_inhead" is called during rendering of the head tag.
Links to CSS and JS files are rendered for you using "include_css" in Jifty::Web and "include_js" in Jifty::Web functions.
Read docs around those methods and Jifty::Manual on adding your own styles and scripts.
Not implemented, but will be as soon as syntax will be defined.
Renders body tag, declares that we're in body and calls "render_page" that actually defines layout of the body. "render_page" method is better target for subclassing instead of this.
Renders the page footer - </html> tag :)
Renders the skeleton of the page and then calls "instrument_content" to prepare and finally render "content_code" using "render_content".
Default layout of the page is the following:
<div> <div> this->render_salutation this->render_navigation </div> <div id="content"><div> this->instrument_content this->render_jifty_page_detritus </div></div> </div>
Something you don't want ever touch. However, does the following:
Renders content of the page - "content_code".
Renders default doctype (HTML5) and opening <html> tag
<html>
Should output nothing but a title tag what will be placed into the head. Title is passed as only argument. Arguments are combined.
Renders the in-page title, followed by page navigation and jifty messages.
See "render_title_inhead", "instrument_content" and "render_header".
Renders link tags which are passed as list of hashes.
Do nothing by default, but link as a hash is passed when content has 'add rel ...' or 'add rev ...'.
Read more in "render_header" and "instrument_content".
Renders "navigation" in Jifty::Web as menu wrapped into a div with id 'navigation'. There is as well page_navigation in Jifty that is rendered in "render_title_inpage" by default.
Called from "render_page".
Renders salutation for the current user wrapped into div with id equal to 'salutation'. Called from "render_page".
Renders admin mode warning, the wait message, and the keybindings javascript. Called from "render_page".
To install Jifty, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Jifty
CPAN shell
perl -MCPAN -e shell install Jifty
For more information on module installation, please visit the detailed CPAN module installation guide.