FeralFormattedEntry
Questions answered by this recipe
How do I separate the display of my text from the text itself?
Description
A directive markup to output text via a template.
Notes
Install by adding:
include_once("$FarmD/cookbook/feralformattedentry.php");
In your local/config.php. (or alternatively specific group's .php, etc.)
Optional.
If you wish to specify a default template page specify it before including, I.e.
$FFETemplate = 'MyFFETemplate'; include_once("$FarmD/cookbook/feralformattedentry.php");
Step by...
include_once("$FarmD/cookbook/feralformattedentry.php");
- Create a template page in the group we wish to use this in, or a central location.
- The default template page name is
FFETemplate
. - Be sure to specify this or your custom template pagename or group.pagename if it is in a different group.
- For convenience you may wish to set the
$FFETemplate
configuration variable to this pagename or group.pagename.
- For convenience you may wish to set the
- The default template page name is
- Add a
(ffe:)...(:ffeend:)
directive to your page; The text within the directive (...
illustrated here), should be presented as the{$$text}
variable in your template page.
That is all there is to it.
Template
How to change the display of your text:
To change how your text is displayed, simply change the template page.
NOTE that in your template page you should include the special variable markup {$$text}
, which will be replaced with the text between the directive markers, else this text will not be displayed.
How to use: (basic)
If no template is specified, the current group's FFETemplate
page is used.
In these examples we will specify our template page in each directive.
(:ffe template=FFEDisplayTemplate:) First line\\ Second line\\ Third line (:ffeend:)
with the FFEDisplayTemplate
template page containing:
{$$text}
Our output will be
First line
Second line
Third line
However, if we change our template only to say,
(:div2 style="border:1px solid purple;":) {$$text} (:div2end:)
Our output will be
First line
Second line
Third line
While just this is useful, we can also specify parameters to the directive and template. See below.
How to use: (advanced)
More useful is when we specify additional parameters for our template. In this example we shall add a parameter called 'header' although we may call it whatever we wish and include as many as we wish (such as header, footer, date, author, category, etc. Whatever YOU want.)
(:ffe template=FFEDisplayTemplate header="Header Text":) First line\\ Second line\\ Third line (:ffeend:)
To get at the 'header' parameter, we use the {$$parameter} notation, in this case {$$header}
.
So, with the FFEDisplayTemplate
template page containing:
!{$$header} {$$text}
Our directive above will result in,
Header Text
First line
Second line
Third line
In this example we have added the 'header' param to our ffe directive and our template; Now every time we use this template page will will need to use this format. This may seem cumbersome at first glance, but more often than not our initial data is fixed and our layout changes later on. With this method our display is dictated by our template page, in this example this is FFEDisplayTemplate
. So if weeks from now we wish to change our layout, for every ffe directive which uses this template page, we simply edit our template page, such as:
with the FFEDisplayTemplate
template page containing:
{$$text} !{$$header}
Our directive above will result in,
First line
Second line
Third line
Header Text
Possible usage:
- blog entries
- forum posts
- Any other standardized data of which you currently have a fixed format.
Release Notes
- 2007-04-18 -- Initial, known bug:
\\
style line continuation in templates will not expand. This is a workaround to make the same line continuation work in posts and related to our markup order. Workaround, er, don't use line continuations in templates.
See Also
Contributors
Comments
See discussion at FeralFormattedEntry-Talk
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.