24,493 ARTICLES
ON THIS WIKI

Module:Itemref


Lua Logo.svg This is the Lua module for Template:Itemref. Below is the documentation for that template.

This template is used to conveniently display an item's icon next to its page link. This is useful on disambiguation pages and tutorial pages. It works like such:

{{itemref|Advanced Monitor}} Advanced Monitor Advanced Monitor

A few additional options can be changed, such as the image size and link text.

{{itemref|Monitor (ComputerCraft)|16px|text=Monitor}} Monitor Monitor

The link itself remains the same, since it should reference the actual item page. The image url should not need to be changed, since images follow a special naming convention that is automatically handled in this template, so the image name should essentially match the item name. If it does not, correct it. In particular, this template looks for "File:Grid <item name>.png" and if it doesn't find it, it will display:

Nonexistent Nonexistent

It is also possible to show the image after the text instead of before it:

{{itemref|Monitor (ComputerCraft)|right=1}}

Monitor (ComputerCraft) Monitor (ComputerCraft)


local p = {}

local g = require("Module:Common")

function p.makeItemref(name, link, text, size, right)
	local image = "Grid " .. name .. ".png"
	link = link or name
	text = text or name
	size = g.px(size or "32px")
	
	local out = '<span class="itemref"'
	if size ~= "32px" then
		out = out .. ' data-size="' .. size .. '"'
	end
	out = out .. ">"
	
	if g.isGiven(right) then
		out = out .. g.link(link, text)
		out = out .. "&nbsp;"
		out = out .. g.img(image, size, link, text)
	else
		out = out .. g.img(image, size, link, text)
		out = out .. "&nbsp;"
		out = out .. g.link(link, text)
	end
	
	out = out .. "</span>"
	
	return out
end

function p.main(frame)
	local frame, args = g.getFrameAndArgs(frame)
	
	return p.makeItemref(args[1], args.link, args.text, args[2], args.right)
end

return p