Wolf tags are similar to XHTML or XML tags. With the WolfTags Plugin enabled, you can use a set of standard WolfTags and even create more of your own.
WolfTags Plugin will add a similar functionality to Wolf CMS as that offered by Radius tags in Radiant CMS (but with a preceding ‘w:’ instead of ‘r:’).
WolfTags may be used in a Page, Snippet, or Layout. See the Sample Layout (included) for further examples of usage.
Optional: To allow execution of PHP code as common in Wolf CMS add the line:
define(ALLOW_PHP, true);
to WOLF_ROOT/config.php
. (As this file is normally not writable you have to give yourself write permission to that file first!) Otherwise, only WolfTags will be available for dynamic functions in the backend.
The following example shows how Wolf tags can be defined:
include_once(CORE_ROOT.'/plugins/wolf_tags/index.php'); class MyTags extends WolfTags { public function tag_title() { return $this->page->title(); } }
As you can guess the tag defined above will output the current page’s title.
The WolfTags Plugin will automatically collect all methods whose names start with tag_
and whose classes are derived from class WolfTags
.
The include line is required to ensure that the class WolfTags
is defined before it is used to derive another class from it.
WolfTags can be included on pages which use either the Textile or Markdown text filter. (And usage with Textile does not require any “notextile.” markup.)
The WolfTag defined above could be used inside a page like this:
Welcome to page <w:title />
The following is also allowed:
Welcome to page <w:title></w:title>
It is possible to pass arguments to a tag in the usual format argument="value"
. For example:
Welcome to page <w:title uppercase="yes" />
The arguments passed can be accessed inside a tag definition using the array $args
. For example:
public function tag_title() { if ($this->args['uppercase'] == 'yes') return strtoupper($this->page->title()); else return $this->page->title(); }
To mark an argument as required you can call the method require_argument()
inside the tag definition. This method will return the required argument’s value as well (or throw an exception if the argument has not been passed).
Like HTML tags, Wolf tags can wrap around content as well. For example:
<w:uppercase>Welcome to page <w:title /></w:uppercase>
The content can be accessed inside a tag definition using the member variable $content
. To parse the content and get the parsed result use the method expand()
. For example:
public function tag_uppercase() { return strtoupper($this->expand()); }
It is also possible to pass some default arguments to the child tags. For example:
public function tag_uppercase() { $defaultArgs = array('uppercase' => 'yes'); return $this->expand($defaultArgs); }
To access the parent tag inside a tag definition use the member variable $parent
. As $parent
is a reference any changes made to $parent
will affect the parent tag as well.
As a shortcut, nested tags can be written for example as:
<w:children:each status="all">...</w:children:each>
This is equivalent to:
<w:children status="all"><w:each status="all">...</w:each></w:children>