Module:Loop

Revision as of 02:49, 18 May 2026 by Teeth (talk | contribs) (add repi function for creating repeating css and stuff)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Loop/doc

--[[

This module is for generating looped content in templates and pages.

]]

local p = {}

--[[

Usage: {{#invoke|Loop|repi|i|10|number: i}}
]]
function p.repi( frame )
	local index_var = frame.args[1]
	local repetitions = tonumber( frame.args[2] )
	if not index_var then
		return str._error( 'function repi expects a string as first parameter, received "' .. ( frame.args[1] or '' ) .. '"' )
	end
	if not repetitions then
		return str._error( 'function repi expects a number as second parameter, received "' .. ( frame.args[2] or '' ) .. '"' )
	end
	str = ''
	for i=1,repetitions do
		str = str .. string.gsub(text, index_var, i)
    end
	return str
end

return p