Module:Chapter navigation

From Wikibooks, open books for an open world
Jump to: navigation, search
Documentation[edit] [history] [purge]

This module provides a way to generate navigation bars to navigate between chapters of a book and a way to put a book chapter in the book category.


This module should not be invoked directly. The {{simple chapter navigation}} template should be used instead.


This module provides two functions: one to create a navigation bar and one to categorize the page automatically, assuming it is a book chapter. The former receives two optional arguments, previous and next, which should be the names of the previous and next chapters, respectively. It uses these chapter names to generate a navigation bar that is meant to be put at the bottom of the chapter page. The latter function does not have any parameter and puts the chapter page in the book category, ordering it properly. These two functions assume that the book follows the Wikibooks naming policy and are likely to work improperly if it is not followed.

return {
	navigation_bar = function(frame)
		local current_title = mw.title.getCurrentTitle()
		local base_page_name = current_title.baseText
		if frame.args.bordertopstyle == null then frame.args.bordertopstyle = '' end
		if frame.args.bordertopwidth == null then frame.args.bordertopwidth = '' end
		if frame.args.borderbottomstyle == null then frame.args.borderbottomstyle = '' end
		if frame.args.borderbottomwidth == null then frame.args.borderbottomwidth = '' end
		local bar = mw.html.create('div')
			:css {
				['border-top-style'] = frame.args.bordertopstyle;
				['border-top-width'] = frame.args.bordertopwidth;
				['border-bottom-style'] = frame.args.borderbottomstyle;
				['border-bottom-width'] = frame.args.borderbottomwidth;
				clear = 'both';
				['margin-top'] = "1em";
				['margin-bottom'] = "1em";
				width = "100%";
				height = "20px";
		if frame.args.previous and frame.args.previous ~= '' then
			bar:tag('span'):css('float', 'left'):wikitext('[[' .. base_page_name .. '/' .. frame.args.previous .. '|' .. frame.args.previous .. ']]')
		if and ~= '' then
			bar:tag('span'):css('float', 'right'):wikitext('[[' .. base_page_name .. '/' .. .. '|' .. .. ']]')
		return tostring(bar)
	categorize = function(frame)
		--local current_title = mw.title.getCurrentTitle()
		--return "[[Category:" .. current_title.baseText .. '|' .. current_title.subpageText .. ']]'
                return frame:expandTemplate{title = "BookCat"}