---
name: "Jifty::Plugin::ViewDeclarePage::Page"
section: "3pm"
platform: "linux"
package: "libjifty-perl"
version: "1.10518+dfsg-2"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/Jifty::Plugin::ViewDeclarePage::Page"
---

# Jifty::Plugin::ViewDeclarePage::Page(3pm)

new style page wrapper to simplify customization and reuse.

## NAME

Jifty::View::Declare::Page::NewStyle - new style page wrapper to simplify customization and reuse.

## DESCRIPTION

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;
```

## DIFFERENCES FROM DEFAULT PAGE CLASS

- no calls into templates

  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) }
  ```

- no render\_pre\_content\_hook

  override "render\_content".

- title is always rendered in page

  Even when there is no 'page\_title is ...' in the content code, see "instrument\_content" and "render\_title\_inpage".

- no html in title

  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"

- new 'add rel ...' and 'add rev ...'

  Can be used in the content code to define feeds, relative links and other cool stuff. See "instrument\_content" and "render\_link\_inpage".

- at last

  It's documented!

## ACCESSORS

- content\_code

  Code reference that renders the core of the page, this is code block right after page token in the following example:

  ```
      template 'news' => page {
          ...
      };
  ```

  Is set by jifty during construction of the page object.

- \_meta

  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.

- \_title and \_links

  These are internal temporary holders of corresponding data.

## METHODS

### Initialization and rendering driver

*new*

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.

*init*

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 {
        ...
    };
```

*render*

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".

### Main blocks of the page

*render\_header*

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.

- doctype

  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.

- tag \<link\>, "add rel ..." and "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.

- css and js

  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.

- meta

  Not implemented, but will be as soon as syntax will be defined.

*render\_body*

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.

*render\_footer*

Renders the page footer - \</html\> tag :)

### Body layout

*render\_page*

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>
```

*instrument\_content*

Something you don't want ever touch. However, does the following:

- setups local 'page\_title is ...' handler which calls "render\_title\_inpage" if 'page\_title is' is used.

  - if 'page\_title is' is not used then calls "render\_title\_inpage" after and put result into output stream before the content.

  - setup handler for 'add rel ...' and 'add rev ...', that calls "render\_link\_inpage" and fills \_links accessor.

  - sure calls "render\_content".

  *render\_content*

Renders content of the page - "content\_code".

### Helpers

*render\_doctype*

Renders default doctype (HTML5) and opening `"<html>"` tag

*render\_title\_inhead*

Should output nothing but a title tag what will be placed into the head. Title is passed as only argument. Arguments are combined.

*render\_title\_inpage*

Renders the in-page title, followed by page navigation and jifty messages.

See "render\_title\_inhead", "instrument\_content" and "render\_header".

*render\_links\_inhead*

Renders link tags which are passed as list of hashes.

*render\_link\_inpage*

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".

*render\_navigation*

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".

*render\_salutation*

Renders salutation for the current user wrapped into div with id equal to 'salutation'. Called from "render\_page".

*render\_jifty\_page\_detritus*

Renders admin mode warning, the wait message, the keybindings and PubSub javascript. Called from "render\_page".
