User:Whiteknight/Header Snippets

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This page is going to contain short code snippets that can be copy+pasted into header templates.

Print Versions[edit | edit source]

Want your navigational templates to disappear on the printable version of your book? Use this parser function around your navigational template:

{{#ifeq: {{SUBPAGENAME}} | Print Version || <!--NAVTEMPLATE--> }}

Where "Print Version" is the subpage name of your printable version. For instance, if your print version is located at "My Book/My Print Version", and we wanted our navigational template to be a simple link to the TOC, we could write:

{{#ifeq: {{SUBPAGENAME}} | My Print Version || [[My Book]] }}

Forward and Back Links[edit | edit source]

Want to include forward and back links into your navigational template? If our header template is {{My Template}}, we can include two optional arguments in it like this:

{{My Template|Last Page|Next Page}}

In our template, we can write this to create a forward link in our page, or no link if we don't have a "previous page" (such as the first page of your book):

{{#if: {{{1|}}} | ← [[My Book/{{{1}}}|{{{1}}}]] | }}

Similarly, we can create an optional "next" link:

{{#if: {{{2|}}} | [[My Book/{{{2}}}|{{{2}}}]] → | }}

Putting these together, we can create a template with a forward link, a back link, and a link to the TOC in the middle:

{{#if: {{{1|}}} | ← [[My Book/{{{1}}}|{{{1}}}]] — | }}
[[My Book]]
{{#if: {{{2|}}} | — [[My Book/{{{2}}}|{{{2}}}]] → | }}

Named Variables[edit | edit source]

If you would prefer to use named parameters instead of the default numbered parameters, you can write this instead:

{{#if: {{{last|}}} | ← [[My Book/{{{last}}}|{{{last}}}]] | }}

and:

{{#if: {{{next|}}} | [[My Book/{{{next}}}|{{{next}}}]] → | }}

Simple Last and Next Links[edit | edit source]

If you don't want the page titles to appear in the forward and backward links, you can modify the code above to print simply "next" or "last":

{{#if: {{{1|}}} | ← [[My Book/{{{1}}}|Last]] | }}

and

{{#if: {{{2|}}} | [[My Book/{{{2}}}|Next]] → | }}

Likewise, you can replace all the instances of the number "1" with the word "last" and all instances of the number "2" with the word "next", if you want to use named paramters instead.

Top Links[edit | edit source]

To make a link appear at the very top of the page, to the left of the page title, you can use the following span:

<span id="top-navigation" class="subpages noprint">...</span>

The links will appear at the top of the page, and will be disabled during printing.