S2 Cookbook: Pages

From Dreamwidth Notes
Jump to: navigation, search

All S2 code operates within the context of a Page class.

Also see these chapters for specific page examples:

Get the current Page

Use the get_page() function to get the current page:

var Page p = get_page();

Alternatively, if the function you are coding in belongs to the Page class or one of its subclasses, you can also use $this to refer to the current Page being rendered, or even the $. shorthand:

# these both print the same thing if used inside a
# Page class or subclass function
# in this case--the title to the journal
print $this.global_title;
print $.global_title;

Get the current page's view type

The view Page class member indicates a page's current view type, which can be one of:

  • recent
  • read
  • network
  • archive
  • tags
  • reply
  • month
  • day
  • entry

Examples:

# get a Page variable, if you don't have one available
# in the current function
var Page p = get_page();
var string $view = $p.view;
 
# these can be used inside Page class and subclass functions and 
print $this.view;
print $.view;