وحدة:RelatedPages
من قصص عارف
local p = {}
function p.render(frame)
-- Get arguments from the template
local args = frame:getParent().args
local html = mw.html.create('div'):addClass('related-pages-container')
-- Create a list container
local list = html:tag('ul'):addClass('related-pages-list')
-- Iterate through the provided pages
local i = 1
while args['title' .. i] do
local title = args['title' .. i] -- Title entered by the user
-- Manually replace spaces with underscores and encode using mw.uri.encode with PATH
local encodedTitle = mw.uri.encode(title:gsub(" ", "_"), "PATH")
local link = "https://3arf.org/stories/wiki/" .. encodedTitle
local image = args['image' .. i]
-- Create the list item for each related page
local item = list:tag('li'):addClass('related-page-item')
-- Create the image tag
local imgTag = mw.html.create('img')
:attr('src', image)
:attr('alt', title) -- Use title for alt text
:addClass('related-page-thumbnail')
-- Create the link structure
item:tag('a')
:attr('href', link) -- Use the generated link
:wikitext(tostring(imgTag)) -- Convert the image tag to string
:wikitext('<span class="related-page-title">' .. title .. '</span>')
i = i + 1
end
return tostring(html)
end
return p