Module:GetRels

From Bodhicitta
Revision as of 13:02, 3 July 2024 by Jeremi (talk | contribs) ((by SublimeText.Mediawiker))

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

local p = {}

function p.main(frame)

	local pagename = mw.title.getCurrentTitle().text
	local pdata = mw.loadData('Module:GetData/relationships')
	local pargs = frame:getParent().args
	if not pdata then
		return 'No relationships!'
	else
		local output = '<h1>Relationships</h1><table class="smwtable-clean th-top-right th-nowrap border">'

		if type(pdata) == "table" then
		    for _, data in ipairs( pdata ) do
		    	local relatedString = ''
				for relatedTo in string.gmatch(data.RelatedTo, "([^;]+)") do
					if relatedTo == pagename then
					    relatedString = relatedString .. '<div><i class="fa-duotone fa-arrow-right" style="color: blue;"></i> [[' .. relatedTo .. ']]</div>'
					else
					    relatedString = relatedString .. '<div><i class="fa-duotone fa-arrow-left" style="color: green;"></i> [[' .. data.wikipage .. ']]</div>'
					end
				end
		    	output = output .. '<tr><th>' .. data.Relationship .. '</th><td>' .. data.wikipage .. ': ' .. relatedString .. '</td></tr>'
		    end
		end

		output = output .. '</table>'

		return output
	end
end

return p