FANDOM


Nuvola apps importantThis software is deprecated in favor of Portable Infoboxes, and has limited support from FANDOM.

The Lua InfoboxBuilder greatly simplifies the creation of infoboxes. What's more, it makes pages render faster than those that use infoboxes built with traditional wikitext. Improvements in rendering time are increasingly obvious with more complicated infoboxes. While any community would benefit from using Lua, you should definitely consider using the Lua InfoboxBuilder if your infoboxes contain nested templates.

Because it uses Lua, a fully-fledged programming language, the InfoboxBuilder allows you to create infoboxes that are as complicated as you wish — based upon a highly simplified, standardized core. No matter where you are on the FANDOM network, you'll recognize the "guts" of the Lua Infobox, but you won't be a slave to its simplicity. The Lua InfoboxBuilder offers you an easy way to create infoboxes, without losing the ability to make them completely your own.

What do I need?

The InfoboxBuilder is now a parser function and is enabled automatically.

Creating a simple infobox

Just a simple infobox
Moon
FAQ
Is it simple?Yes, it is!
Will I use it?Every time!

If you want to create a simple infobox - it is really easy to do. The source code of the one on the right is:

{{#infoboxbuilder:
|  1:Type  = Title
 | 1:Value = Just a simple infobox

|  2:Type  = MainImage
 | 2:Value = [[File:Moon.jpg]]

|  3:Type  = Header
 | 3:Value = FAQ

|  4:Type  = Line
 | 4:Label = Is it simple?
 | 4:Value = Yes, it is!

|  5:Type  = Line
 | 5:Label = Will I use it?
 | 5:Value = Every time!
}}

InfoboxBuilder comes with a default theme which is meant to look good on any background.

The syntax

InfoboxBuilder uses the new syntax which is meant to be simple, yet descriptive.

The general pattern for each argument is:
| [Index]:[Key] = [Value]
Every row must have a numerical index that defines its place in the infobox and groups the arguments. The basic ones are Type and Value. You can use the following Types:
  • Title
  • Header
  • Line
  • Image
  • MainImage
  • Footer
  • Custom

Line and Custom require using a Label argument. For Line it defines a label of a field and for Custom it defines an HTML tag that you want to use as a container (e.g. div, span). You can also use Label to define captions of an Image or a MainImage field.

Split type

Split type builds on 4 elements. These elements coincide with left and right column, as seen in example below. Just as with other types, you can assign a method to each Label and Value.

{{#infoboxbuilder:
|  1:Type  = Title
 | 1:Value = Just a simple infobox

|  2:Type  = Split
 | 2:LabelLeft = Left label!
 | 2:ValueLeft = Left value!
 | 2:LabelRight = Right label!
 | 2:ValueRight = Right value!
}}

Custom type

Custom type wraps the "value" using a XML or html tag. The example below show the creation of an unordered list:

{{#infoboxbuilder:
|  1:Type  = Title
 | 1:Value = Just a simple infobox

|  2:Type  = Custom
 | 2:Label = ul
 | 2:Value = <li>8 </li><li>k</li>
}}

Tweaking an infobox

Variables

There are several ways you can modify a look or a behavior of your infobox by using Variables arguments. They all have an index of 0. The default ones are:

| 0:Theme                   = default, -- Adds prefix to CSS classes 
                                       -- (prefix you want to use)
| 0:CustomModule            =  ,       -- Defines a path to a Lua module with custom functions
                                       -- (name of module with a Module: prefix)
| 0:MainImageCaption        = Off,     -- Toggles display of Label in the Main Image field
                                       -- (Off/On)
| 0:ToggleContentLongerThan = 1000     -- Makes fields with long values collapsible
                                       -- (number of characters)
To overwrite them just put it in the source of your infobox with a different value:
Just a simple infobox
Moon
The same infobox but with a caption and custom styling.
FAQ
Is it simple?Yes, it is!
Will I use it?Every time!
{{#infoboxbuilder:
|  0:MainImageCaption = On
|  0:Theme            = my-theme

|  1:Type  = Title
 | 1:Value = Just a simple infobox

|  2:Type  = MainImage
 | 2:Label  = The same infobox but with a caption and custom styling.
 | 2:Value = [[File:Moon.jpg]]

|  3:Type  = Header
 | 3:Value = FAQ

|  4:Type  = Line
 | 4:Label = Is it simple?
 | 4:Value = Yes, it is!

|  5:Type  = Line
 | 5:Label = Will I use it?
 | 5:Value = Every time!
}}

You can also define your own variables, for example if you want to use a {{PAGENAME}} magic word add:

| 0:Pagename = {{PAGENAME}}

{{#invoke:Source | Link | MediaWiki:Common.css}} The pagename of an article using this infobox will be passed now for a later use.

Styling

All of this would not be worth much if you couldn't style your brand new infobox. Each element of an infobox has a specific class name with a prefix specified in the Theme variable (e.g. if the prefix is "default" a container div will have a class name "default-infobox-container").

On top of that, each type can also have their own CSS class if one type should be different from another as seen in the example below:

{{#infoboxbuilder:
|  0:Theme = my-theme

|  1:Type  = Title
 | 1:Value = Just a simple infobox

|  2:Type  = Line
 | 2:Label = Am I a line?
 | 2:Value = Yes, but customised!
 | 2:CssClass = CustomLine
}}

We recommend to put all of the CSS code in a MediaWiki:Common.css article. You can use the my-theme theme as a starter.

Complex infoboxes with custom Lua modules

InfoboxBuilder
Lua
Basic Information
Module's nameInfoboxBuilder
DependenciesInfoboxBuilderView; HF (all are required)
VersionBeta

InfoboxBuilder works fine for simple infoboxes, but the real magic happens with complex infoboxes that use a lot of logic. The most important thing here is that you can include your own Lua module that handles the logic. But, first things first.

Step 1 - Provide data

Infoboxes that already exist

When you convert an existing wikitext template to Lua, you don’t lose all the hard work you’ve put into every page that uses it. Say you’ve filled out a wikitext infobox on Batman that looks like this:

{{hero
|name            = Batman
|secret identity = Bruce Wayne
|headquarters    = Batcave
|arch-enemy      = Joker
}}

When you convert {{hero}} to use Lua, you lose none of that data! It's all automatically picked up by the new, Lua-based code.

So don't worry: converting to Lua does not mean you're going to have do a ton of work on your site.

New infoboxes

However, if you write a new template you need some input. In this example we will use this wikitext code:

{{LuaInfobox
| ModuleName       = InfoboxBuilder
| ModuleImage      = [[File:Lua.png]]
| Dependencies     = InfoboxBuilderView; HF
| DependenciesDesc = (all are required)
| Version          = Beta
}}

It calls a Template:LuaInfobox article and passes some info about the InfoboxBuilder module. You can find this code in the beginning of this article.

Step 2 - Infobox Template

{{#invoke:Source | Link | Template:LuaInfobox}} At first, we will create a template to model our infobox. To be consistent with the data from Step 1 let's call it Template:LuaInfobox. We will also use the my-theme theme from Common.css. To use a Custom Module, we need to put its name in a 0:CustomModule variable:

{{#infoboxbuilder:

   | 0:Theme        = my-theme
   | 0:CustomModule = Module:LuaInfobox

   |   1:Type  = Title
     | 1:Label = Module name
     | 1:Value = {{{ModuleName|}}}
   
   |   2:Type  = MainImage
     | 2:Label = Module's logo or Lua logo
     | 2:Value = {{{ModuleImage|}}}
 
   |   3:Type  = Header
     | 3:Label = Basic info
     | 3:Value = Basic Information
 
   |   4:Type  = Line
     | 4:Label = Module's name
     | 4:Value = {{{ModuleName|}}}
   
   |   5:Type        = Line
     | 5:Label       = Dependencies
     | 5:Value       = {{{Dependencies|}}}
     | 5:ValueDesc   = {{{DependenciesDesc|}}}
     | 5:ValueMethod = Dependencies
   
   |   6:Type  = Line
     | 6:Label = Version
     | 6:Value = {{{Version|}}}

}}

Step 3 - Custom modules

{{#invoke:Source | Link | Module:LuaInfobox }} CustomModule = Module:LuaInfobox

Custom module's code

local HF = require('Module:HF') 

local LuaInfobox = {}

function LuaInfobox.Dependencies( field, vars )
  local output = ""

  local dependencies = HF.explode( ";", field.Value )

  for i, dependency in ipairs( dependencies ) do
    output = output .. "[[Module:" .. dependency .. "|" .. dependency .. "]]" .. "; "
  end

  if string.sub( output, -2, -1 ) == "; " then
    output = string.sub( output, 1, -3 ) -- Remove last semi-colon and space
  end

  return output
end

return LuaInfobox

Every method retrieves two arguments - table of a field with names of keys matching the ones from a template (e.g. Type, Label, Value) and a similar table of variables (e.g. Theme, Pagename).

As you can see you are able to require other Lua modules so you don't have to store everything in one place. Be careful however, because Lua's engine has a limit of 100 modules included at once.

Usage in a template

Now we need to instruct InfoboxBuilder to use this method for a Dependency field and it is done by adding a ValueMethod argument with a function's name:

    |   5:Type        = Line
      | 5:Label       = Dependencies
      | 5:Value       = {{{Dependencies|}}}
      | 5:ValueMethod = Dependencies

There is no naming convention to stick to, however using a module's name for a main variable and fields' names for functions will help you keep things organised. You can also process Labels in the same way. Just add LabelMethod argument with a name of a function you want to use.

Multiple values

Since every method has access to all arguments grouped in one field you can pass multiple values to it. For example - we want to point that all dependencies are required. We can do it by adding a new argument to the Dependencies field:

  |   5:Type        = Line
    | 5:Label       = Dependencies
    | 5:Value       = {{{Dependencies|}}}
    | 5:ValueDesc   = {{{DependenciesDesc|}}}
    | 5:ValueMethod = Dependencies

and define its value in an article:

| Dependencies     = InfoboxBuilderView; HF
| DependenciesDesc = (all are required)

Now we can use it to add additional notes to the Dependencies field:

function LuaInfobox.Dependencies( field, vars )
  local output = ""

  local dependencies = HF.explode( ";", field.Value )

  for i, dependency in ipairs( dependencies ) do
    output = output .. "[[Module:" .. dependency .. "|" .. dependency .. "]]" .. "; "
  end

  if string.sub( output, -2, -1 ) == "; " then
    output = string.sub( output, 1, -3 ) -- Remove last semi-colon and space
  end

  if not HF.isempty( field.ValueDesc ) then
    output = output .. " " .. field.ValueDesc
  end

  return output
end

Start a Discussion Discussions about Lua templating/InfoboxBuilder

  • Infobox

    19 messages
  • Infobox converting

    4 messages
    • We're only talking about 8 Infoboxes, and they look like they're pretty standard out of the starter kit. I think we can he...
    • Indeed, I've only seen one infobox being used in the wiki. Also, I didn't spot any Lua infoboxes, in a quick search and th...

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.