HFS: Template macros: Difference between revisions

From rejetto wiki
Jump to navigation Jump to search
Line 36: Line 36:
:; can recur : true if the option ''Recursive listing'' is enabled
:; can recur : true if the option ''Recursive listing'' is enabled
:; can archive : true if the current folder is archivable
:; can archive : true if the current folder is archivable
; not | A : true if A is not true
; and | A | B : true if both A and B are true
; or | A | B : true if any of A or B are true
; xor | A | B : true if A is true while B is false, or the opposite
; urlvar | A : url variable. Let's say in the url you see <tt>?sort=s</tt> and you want to know that '''s''', just use the macro urlvar|sort.
; urlvar | A : url variable. Let's say in the url you see <tt>?sort=s</tt> and you want to know that '''s''', just use the macro urlvar|sort.
; header | A : get any value from the HTTP request header. A is the name of the header field. This is something mostly for techies. Don't fret if you don't even know what the header is.
; header | A : get any value from the HTTP request header. A is the name of the header field. This is something mostly for techies. Don't fret if you don't even know what the header is.
; load | A : you'll love this one. You can specify A as a file name, or as a URL. It will load and expand to it. The file or URL you specify must be accessible from the server machine. A can be <tt>C:\windows\win.ini</tt> or also <tt><nowiki>http://another_hfs_in_lan/the_file_i_want.txt</nowiki></tt>.
; load | A : you'll love this one. You can specify A as a file name, or as a URL. It will load and expand to it. The file or URL you specify must be accessible from the server machine. A can be <tt>C:\windows\win.ini</tt> or also <tt><nowiki>http://another_hfs_in_lan/the_file_i_want.txt</nowiki></tt>.

Revision as of 06:22, 15 November 2007

Please note: Macros are not available in current version 2.2, but they will in 2.3, and you can experiment with it using beta versions.

How macros work

Differences with symbols

Macros are similar to symbols. They are something you type in the template and is substituted (we say expands to) with meaning content when the user watch the page.

While symbols are just a name, macros have a name and optionally parameters.

You can tell symbols by macros because symbols are surrounded by %percent% signs, macros are surrounded by {{double braces}}.

More on them

How the macro will work depends on the parameters. The same macro has a different effect when the parameter change.

The macro section will copy the content of a section of the template. But which section is specified by the parameters. So, you have one macro, section, but it will expand to any content as you change the name of the section (as parameter). Let's say {{section|style}} and it will copy the content of section [style].

Parameters

After the name of the macro you can put a character "|" (its name is pipe) and then a parameter: {{name|parameter}}. If the macro requires more parameters, like 2 or 3, you just add more pipes: {{name | parameter | another parameter | don't look at me}}.

Readability

Having macro in macro, nested, can be a mess to read. To increase readability you can

  • split the syntax over several lines, and indent.
  • add a final /macroname to know that you are closing just that macro, like {{load | something /load}}. The final /load is ignored by hfs, it's just for your convenience.

Full list

With letters we are denoting parameters, and their meaning is explained immediately after.

if | A | B | C
if A is true, then it expands to B, else it expands to C. When it expands to B, C is just discarded, and the vice versa. C is optional.
How you tell A is true? A is true if it is not empty and not just a zero. So if A is "hi there!", then it is true.
if not | A | B | C
same as if, but the logic is inverted. When A is true it expands to C and vice versa.
get | A
where A is the name of a value you are interested in, like to know if an option is enabled or not.
This is a list of supported values for A:
can upload
true if in the current folder the user is allowed to upload files
can recur
true if the option Recursive listing is enabled
can archive
true if the current folder is archivable
not | A
true if A is not true
and | A | B
true if both A and B are true
or | A | B
true if any of A or B are true
xor | A | B
true if A is true while B is false, or the opposite
urlvar | A
url variable. Let's say in the url you see ?sort=s and you want to know that s, just use the macro urlvar|sort.
header | A
get any value from the HTTP request header. A is the name of the header field. This is something mostly for techies. Don't fret if you don't even know what the header is.
load | A
you'll love this one. You can specify A as a file name, or as a URL. It will load and expand to it. The file or URL you specify must be accessible from the server machine. A can be C:\windows\win.ini or also http://another_hfs_in_lan/the_file_i_want.txt.