Fandom

Community Central

Comments115

Introducing Lua, for faster and more powerful templates

Grunny June 11, 2014 User blog:Grunny

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.

Hi, everyone! If you don't know me already, I'm Grunny and I'm a software engineer here at Wikia. I'm here to introduce Lua, a new templating language, which we'll be rolling out to all wikias in the near future. This will make it easier for you to create and modify templates such as infoboxes, navigation tables, and many others.

Why are we introducing Lua templates? Edit

MarvelCharacterTemplate

Can't understand all that coding? Try out Lua!

Most of you probably make use of templates on a regular basis. The MediaWiki platform upon which Wikia is built, makes use of special wikitext syntax such as parser functions to let you use logical operations and other features to build templates. The introduction of parser functions effectively turned wikitext into a limited programming language. While parser functions allow you to do many things in templates, complex templates result in performance issues and slow page load times, and are often difficult for users to edit and understand. If you're not sure what parser functions are, then you can see why templates can be complicated!

For this reason, support for Lua as a templating language has been added to MediaWiki, including on Wikia, so you will be able to use a simpler, faster, and more powerful template language. For template editors, Lua will allow you to create a complex template and do things that were either too complex or slow in wikitext. Lua was designed to be relatively easy to learn, and has been successfully used in gaming environments such as World of Warcraft where people with no programming experience have been able to modify their environment by learning a bit of Lua. For those who don't edit templates, you'll still benefit from faster page load times for pages using Lua templates. From converting the character infobox on Marvel Database to Lua, we've seen pages that use it load 35-50% faster!

What does a Lua template look like? Edit

Lua templates are created by writing the Lua code in the Module: namespace. Then they can be used by adding the parser function {{#invoke:}} to a page or template. As an example of a template that just prints out a greeting to a name passed to it, you might create Module:Greeting with the following content:

local p = {}
 
function p.hello( frame )
    return 'Hello, ' .. frame.args[1] .. '!'
end
 
return p

Then, to use the template on a page (or within a template), you would add {{#invoke:Greeting|hello|Wikia}}. This would print out the text "Hello, Wikia!".

Where can I learn more about Lua? Edit

We've started documenting our version of the Lua templating extension (called Scribunto) on Wikia Developers Wiki, and we'll be continuing to expand and improve that documentation as we roll the feature out. You can also visit the Lua website, and take a look at some of Wikipedia's Lua documentation, Lua modules, and templates making use of Lua, as they are using Lua for most things nowadays.

What's next? Edit

Stay tuned for more updates as we roll out Lua templates to more wikias. We'll be posting updates about cool new features, and as we look at enabling it site-wide, we'll be running some training sessions on Wikia Developers Wiki for those who may be interested.

Want to receive updates on the latest Staff blog posts? Then click here to follow this blog.

Also on Fandom

Random Wiki