Frog tags are very similar to HTML tags. With FrogTags Plugin plugin enabled, you can use some standard Frog tags and first of all easily create own Frog tags.
FrogTags Plugin will add the same functionality to Frog CMS as offered by Radius tags in Radinat CMS (but with a preceding ‘f:’ instead of ‘r:’).
To allow execution of PHP code as common in Frog CMS add the line
define(ALLOW_PHP, true);
to FROG_ROOT/config.php
. (As this file is normally not writable you have to give yourself write permission to that file first!)
The following example shows how Frog tags can be defined:
include_once(CORE_ROOT.'/plugins/frog_tags/index.php'); class MyTags extends FrogTags { public function tag_title() { return $this->page->title(); } }
As you can guess the tag defined above will output the current page’s title.
The FrogTags Plugin will automatically collect all methods whose names start with tag_
and whose classes are derived from class FrogTags
.
The include line is required to assure that the class FrogTags
is defined before it is used to derive an other class from it.
The above defined tag could be used inside a page as in the following example:
Welcome to page <f:title />
The following is allowed aswell:
Welcome to page <f:title></f:title>
It is possible to pass arguments to a tag in the usual format argument="value"
. For example:
Welcome to page <f:title uppercase="yes" />
The passed arguments 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 argument you can call the method require_argument()
inside the tag definition. This method will return the required argument’s value aswell (or throw an exception if the argument has not been passed).
Like HTML tags Frog tags can have some content aswell. For example:
<f:uppercase>Welcome to page <title /></f: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 aswell.
As shortcut nested tags can be written for example as:
<f:children:each status="all">...</f:children:each>
This is equivalent to:
<f:children status="all"><f:each status="all">...</f:each></f:children>