Sign In
Start Page | Recent Changes | All Pages | Orphan Pages | Junebug Help

How To Define Global Tags

Global tags are Radius rags like that work on all pages and do not require specifying a Behavior for the page.

If you have deployed Radiant with the—unpack switch, you can edit app/models/page_context.rb directly.

Alternatively you can write an extension, as covered in Creating_Radiant_Extensions?.

Examples

If Children Exist

To create a new tag that only renders its content when the current page has children, use this code
{{{
tag "if_children" do |tag|
  tag.expand if tag.locals.page.has_children?
end
}}}

Then in your page write

{{{
}}}

This will create a unordered list of links to the children of the page, sorted by ascending title, if any exist.

Random Child Page

{{{
tag "children:random" do |tag|
  children = tag.locals.children
  if children.size > 0
    index = rand(children.size)
    tag.locals.page = children[index]
    tag.expand
  end
end
}}}

Then in your page, write

{{{ }}}

Or just

{{{ }}}

Note that this will only select one child page, and needs modification to select more than one.

Refer to the Parent Page

{{{ tag “parent” do |tag| tag.locals.page = tag.locals.page.parent tag.expand if tag.locals.page.has_parent? end

tag “if_parent” do |tag| tag.expand if tag.locals.page.has_parent? end

tag “unless_parent” do |tag| tag.expand unless tag.locals.page.has_parent? end }}}

In your page, write this:

{{{ Go up }}}

This will create a link to the parent page that says “Go up”.


Version 7 | Other versions: « older newer » current versions
Page last edited by rnhurt on November 11, 2007 01:31 AM (diff)