Difference between revisions of "S2 Cookbook: Pages"

From Dreamwidth Notes
Jump to: navigation, search
m (Get the current page's view type)
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
 
== Get the current Page ==
 
== Get the current Page ==
  
Use the [http://www.dreamwidth.org/customize/advanced/layerbrowse?id=core2#func.get_page%28%29 get_page()] function to get the current page.
+
Use the [http://www.dreamwidth.org/customize/advanced/layerbrowse?id=core2#func.get_page%28%29 get_page()] function to get the current page:
 +
 
 +
<syntaxhighlight lang="s2">
 +
var Page p = get_page();
 +
</syntaxhighlight>
 +
 
 +
Alternatively, if the function you are coding in belongs to the <code>Page</code> class or one of its subclasses, you can also use <code>$this</code> to refer to the current Page being rendered, or even the <code>$.</code> shorthand:
 +
 
 +
<syntaxhighlight lang="s2">
 +
# 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;
 +
</syntaxhighlight>
  
 
== Get the current page's view type ==
 
== Get the current page's view type ==
 +
 +
The <code>view</code> 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:
 +
 +
<syntaxhighlight lang="s2">
 +
# 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;
 +
</syntaxhighlight>
  
 
[[Category: S2 Cookbook]]
 
[[Category: S2 Cookbook]]

Latest revision as of 03:12, 8 August 2010

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;