Module:Listbox: Difference between revisions

Want an adless experience? Log in or Create an account.
match expanded {{Main}} in the case that it's in a transcluded page
(allow display names that differ from page names)
(match expanded {{Main}} in the case that it's in a transcluded page)
Line 7: Line 7:
   for _, section in ipairs( sections ) do
   for _, section in ipairs( sections ) do
     local mainTemplate = section.summary:match( '%{%{Main|(.-)}}' )
     local mainTemplate = section.summary:match( '%{%{Main|(.-)}}' )
     local link = mainTemplate and mw.text.split( mainTemplate, '|' )[1]
    -- !!!! This may break if Template:Main is modified !!!!
    local expandedMainTemplate = section.summary:match( 'Main article: %[%[(.-)]]' )
     local link = mainTemplate and mw.text.split( mainTemplate, '|' )[1] or expandedMainTemplate and mw.text.split( expandedMainTemplate, '|' )[1]
     list:tag( 'li' )
     list:tag( 'li' )
       :wikitext( '[[' .. (link or section.name) .. '|' .. section.name .. ']]' )
       :wikitext( '[[' .. (link or section.name) .. '|' .. section.name .. ']]' )
Line 65: Line 67:
     args = {
     args = {
       [1] = "The Legend of Zelda",
       [1] = "The Legend of Zelda",
       [2] = "Characters"
       [2] = "Locations"
     }
     }
   } end
   } end