Module:File link/doc
![]() | This is a documentation subpage for Module:File link. It may contain usage information, categories and other content that is not part of the original module page. |
This module is used to construct wikitext links to files, using a fluent Lua interface. This is done by creating a fileLink object, which has various methods corresponding to different file link parameters. The module is used from other Lua modules, and cannot be used directly from wiki pages.
Usage
Creating the object
First, you need to import the module.
local fileLink = require('Module:File link')
Then, create the object using the fileLink.new
function. The first parameter is the filename, and is optional.
local obj = fileLink.new('Example.png')
Basic usage
You can add parameters to the file link using the fileLink object's methods. (See the Methods section below for the full list.)
obj:width(220)
obj:alt('The alt text')
obj:caption('The caption.')
You can then produce the link wikitext using the object's render
method.
obj:render()
Call-chaining
All the object's methods apart from the render
method return the object itself, so can be used to call-chain.
obj:width(220):alt('The alt text'):caption('The caption.'):render()
Apart from the name
method, all of the object's methods support nil
as an input, so call-chaining can be performed with variables whose value is unknown. However, an error will be raised if the input is of an unsupported type for that method. Please see the Methods section for supported input types for each method.
Use with tostring
Instead of using the render
method, you can call tostring
on the object to create the link wikitext.
obj:width(220):alt('The alt text'):caption('The caption.')
tostring(obj)