Macros

Everything that we have discussed so far cannot be altered or extended (or, at least, it's not easy—I mean, the Redmine API does not allow you to do this). However, Redmine also supports Wiki macros that are intended to be extended. This means that third-party plugins can bring in their own macros into Redmine.

The syntax of a Wiki macro looks like this:

{{MacroName(Arguments)}}

So, let's review those macros that are introduced by the Redmine core.

The Table of contents macro

Actually, Table of contents is not a macro, technically. However, it's reviewed here as its syntax resembles macros:

{{toc}}

This rule—if it's the only one on a line and is separated by empty lines from other paragraphs—generates the table of contents, as seen in the following screenshot:

The Table of contents macro

The table of contents that is generated by the {{toc}} rule can also be aligned. Thus, to align it to the right, use {{>toc}}, and to align it to the left of the text, use {{<toc}}.

The Collapse macro

Sometimes, you may need to publish some less important details. The problem is that such information is going to occupy some space on the page and, probably, take attention away from the more important things. This is when the {{collapse}} macro comes in handy:

{{collapse(hint)
text
}}

This macro makes text invisible and shows only hint by default. Also, hint is rendered as a link; clicking on it unhides text:

The Collapse macro

The Thumbnail macro

What if you want to embed an attached image in a different size? Of course, you can have a separate attachment for each size. You can also use the advanced options (see the appropriate subsection later) to resize the image in the browser using CSS, but in this case it is going to be resized each time the user loads the Wiki content. Therefore, for such cases, Redmine provides the {{thumbnail}} macro, which has the following syntax:

{{thumbnail(image.png, size=100, title=Title)}}

Here, image.png must be attached to the current resource, size specifies the size of the thumbnail, and Title is its title.

Note

Thumbnails not shown?

To generate thumbnails, Redmine uses ImageMagick's convert tool, which is probably missing on your installation. Check out Chapter 2, Installing Redmine, to learn how to install it.

The Include macro

If you need to copy some common text—such as a disclaimer or rules—into multiple Wiki pages, you can create a separate page with the common content and then include it in other pages using the {{include}} macro. The syntax of this macro is as follows:

{{include(Project:Name)}}

Here, Project is the project identifier and is optional. It is needed only if you are going to include a Wiki page from another project. Name is the name of the Wiki page to be included.

The Child pages macro

The Wiki navigation is built by Wiki writers through an extensive use of Wiki links. That's how Wiki systems work. However, nothing prevents Redmine from assisting with this by introducing the {{child_pages}} macro, which has the following syntax:

{{child_pages(Name, parent=1, depth=2)}}

Here, Name is the name of the Wiki page whose child pages are to be listed. If Name is omitted, Redmine will use the current Wiki page (and if the macro is not executed within a Wiki page, an error will be raised). If the parent option is enabled (that is, set to 1), the list will include the current page as well. The depth option controls the depth up to which child pages should be listed.

The following screenshot shows a sample output:

The Child pages macro

The Hello world macro

This macro was created for educational and testing purposes. It just outputs the given arguments and text, if any:

{{hello_world(argument=1)
Text
}}

So, you can play with this macro to learn the syntax of macros.

The Macro list macro

If a plugin ships with a macro, how do you know that it is available? That's where {{macro_list}} can help. This macro outputs short information about the macros that are available in the current Redmine installation.

The syntax is simple:

{{macro_list}}

Tip

If you are using plugins that provide custom macros, it can be a good idea to create a special Wiki page named, for example, Help, with a list of all available macros.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset