FANDOM


  • I'm an admin on a video game related wiki, and we have a set of pages that have similar data in their infobox.

    I'd like to 'tableize' the source data in a Lua module, and just call something like this, where the function would fetch the data and build an infobox:

    {{#invoke:Pets|infobox|poultry}}

    ...on the page(s) that will require the infobox to have an infobox generated.

    This way, when a game update comes by, I could just change the page where the source data and the Pets' module infobox function to update all the places where we have an infobox.

    I've read that once we get to the module part, templates have already been expanded, parser functions and extension tags have already been processed, and pre-save transforms (e.g. signature tilde expansion and the pipe trick) have already happened. (Source)

    Is it possible? If not, is there an alternative that I could go with to achieve similar results?

    Thanks!


    I have only tried to make a module (the Hello world), so I'm not a Lua/Module guru yet.

      Loading editor
    • it is not portable infobox. it's just a table. however, you can create portable infobox via module, of course: create wikitext, then frame:preprocess it.

        Loading editor
    • Ok, so frame:preprocess will process the wikitext. Do you mean that I could then use a template which contains the <infobox> (and others) tag?

      Do you know of an example that does this?

        Loading editor
    • it would be better to just create the module and work with it, than re-asking same question. you will never understand scribunto unless you will try it, not matter of count of questions.

      here is example of the module that calls portable infobox template. but you don't need it. just create a module by yourself: it will be much better, than dealing with alien (in all meanings of the word) code.

        Loading editor
    • Yeah, I will try that, I just couldn't tackle any code until later tonight!

      Thanks for the pointer, looks good.

        Loading editor
    • @Fngplg Hey, thanks a bunch! This thing is magical!!

      https://rappelz.fandom.com/wiki/Module:Pets

        Loading editor
    • your module reparses csv for each module call. you can avoid this by converting csv to lua table. although it will not make any visible difference right now, when you have small data string, it will have growing performance impact when your data will grow.

        Loading editor
    • Thanks; I'll consider that!

      For now, being able to take that data, save it into a local .csv, edit it then plug it back in is a huge benefit for me.

      I'll try and see if I can find a convenient way to convert from .csv to Lua table, and vice-versa.

      Because, yeah, eventually I plan to add a table of 3k+ entries.

        Loading editor
    • for thousands of entries you most likely will not be able ot use csv at all (lua has memory and time limits).

      for big data you woukd like to use mw.loadData. read about this ahead, in order to plan data structure by better way: loaddata will return metatable, so you will need to access to your data via keys in order to not lost performance benefits of the loaddata.

        Loading editor
    • A FANDOM user
        Loading editor
Give Kudos to this message
You've given this message Kudos!
See who gave Kudos to this message
Community content is available under CC-BY-SA unless otherwise noted.