User:ChaoticShadow/Infobox

So, you've got a shiny new wiki and have been eyeing those infoboxes you see on other wikis, but you are unsure how to get started on creating those. The aim of this page is to provide short introduction on how to do just that.

Approaches
Generally speaking, there are 3 ways to make an infobox: wikitext, PortableInfobox (may be referred to as PI later), and Lua. The table below discusses a few pros and cons of each approach. Note that these approaches can call each other in various ways, but for simplicity's sake, let's assume usage is purely with one approach in the comparison below.

For most people, PI will give you what you want for an infobox with few downsides. The only downsides are when you need a pretty custom layout, because otherwise you can usually get away with the  tag as an escape hatch. The syntax of PI is a bit similar to that of HTML, so for those familiar with HTML, this is a relatively easy transition. You can also use wikitext and invoke Lua modules here. For beginners, this is the best option.

However, if all you need is an extremely simple infobox, wikitext can also be option, since it is effectively either a, or a collection of  s and  s using a grid or flex layout. Something to keep is mind is that the more complex a wikitext infobox is, the harder it is to maintain.

For those who want the flexibility of wikitext infoboxes, but also want much better maintainability, Lua is the only option. This is only recommended to those who are willing to learn Lua. There are also two additional benefits other than maintainability. One of the benefits is that the code editor will point out most, if not all, syntax errors, which is a nice feature over the wikitext editors. The other is the ability to use the debug console to track down bugs.

Notice that the wikitext and the Lua approaches are nearly identical in terms of pros and cons; the reason for that is because you'll be eventually creating a  or a bunch of  s in both approaches. The primary difference is the ability to use Lua instead of having to use parser functions. Using Lua can greatly simplify the same logic previously implemented with the aforementioned parser functions. This holds true for templates in general, actually.

Creating your own
Now that you know the 3 main ways to create an infobox, let's actually create some. This isn't a guide, but rather a visual comparison of how each approach can achieve a similar result.

Wikitext
The simplest way to create an infobox is using a table in my opinion.

By giving the table a class you can style it, and any child elements however you want. Making this infobox show more info is as easy as just adding more rows the table.

Wikipedia's Simple Infobox
A more out of the box solution is using Wikipedia's infobox. This will likely require some rules from Wikipedia's Common.css to style properly. It'll also mostly eliminate the need to create your own layouts.

This page is an implementation of above by k6ka on a Miraheze wiki.

PortableInfobox
To create PortableInfoboxes, you'll need the PortableInfobox extension. Without this extension, parser tags for PI will be displayed like text.

Unlike with the wikitext approach, PI comes with styling out of the box, so unless customization is needed to fit the rest of wiki, we're done! If you need more information shown, you'll need to add more tags of the appropriate type.

For more examples and documentation, there are plenty of PI resources out there. Here are a few to get started:
 * https://portability.fandom.com/wiki/Portable_Infoboxes
 * https://community.fandom.com/wiki/Help:Infoboxes#Examples
 * https://portability.fandom.com/wiki/Example_communities#Portable_Infoboxes

Lua
To get started with creating infoboxes in Lua, you'll need the Scribunto extension. Without this, you won't be able to use Lua.

You can create an infobox similar to the ones above by using the mw.html library provided by Scribunto. For more information, see the reference manual on what things you can do. Similarly, the "infobox" class is assigned to the table to allow for easy styling elsewhere.

The following needs to be created on a page in the "Module" namespace, then invoked for it to show (typically in the "Template" namespace). This is different than the two approaches above where the code lives in the "Template" namespace. For example, if the page is named "Module:Infobox demo", you'll need to use  to call the main function defined below.

For simplicity's sake, the Arguments module is imported to grab arguments when the module is invoked.

As you can see, it's rather unwieldy to have to do this all the time, so my personal recommendation when going this route is to create helper module(s) to eliminate some of the boilerplate.

Capiunto
A more out of the box solution is using Capiunto. I haven't used it myself, but it looks pretty good.

Porting from Wikipedia
Copying Wikipedia infobox templates looks easy, but this is very deceiving. Depending on who wrote that infobox, it could have no dependencies, it could have a few dependencies, it could have a hundred dependencies. It's hard to easily tell that from the get go, so take this as a warning. It could pay off by having access to WP's flexible templates in the end, however, you should be familiar with wikitext and Lua before attempting this. You should also be comfortable changing the contents of these dependencies or making replacements (dummy or simplified versions of dependencies) to avoid having unnecessary templates and modules. Quite a few Wikipedia templates require Lua and blindly importing can drag you into dependency hell.

Now, to port from Wikipedia, you'll need to use Special:Export on Wikipedia, and then Special:Import on your wiki. Most of the time importing the infobox alone is not enough, you will need to import its dependencies or else the infobox will be broken.

To find said dependencies in wikitext, you'll need to look for templates embedded in the infobox (denoted by ), modules being invoked by the infobox (denoted by  ). To find dependencies in Lua, you'll need to look for  and   calls.