Module:TemplateStarter: Difference between revisions
// via Wikitext Extension for VSCode Tag: Manual revert |
// via Wikitext Extension for VSCode |
||
| Line 190: | Line 190: | ||
end | end | ||
-- Get list of available templates including | -- Get list of available templates including campaign combinations | ||
function p.getAvailableTemplatesWithVariants() | function p.getAvailableTemplatesWithVariants() | ||
-- Get the filtered list of base templates that are allowed for page creation | -- Get the filtered list of base templates that are allowed for page creation | ||
local baseTemplates = p.getAvailableTemplates() | local baseTemplates = p.getAvailableTemplates() | ||
local | local templatesWithCampaigns = {} | ||
-- Use a map to ensure uniqueness before adding to the final list | -- Use a map to ensure uniqueness before adding to the final list | ||
| Line 204: | Line 204: | ||
end | end | ||
-- Iterate through | -- Iterate through campaigns to find applicable templates | ||
for | if ConfigRepository.campaigns then | ||
for campaignId, campaign in pairs(ConfigRepository.campaigns) do | |||
if campaign.applicable_templates then | |||
for _, templateName in ipairs(campaign.applicable_templates) do | |||
-- Only include if the base template is allowed for page creation | |||
if templateMap[templateName] then | |||
local campaignTemplateName = templateName .. " (" .. campaign.name .. ")" | |||
templateMap[campaignTemplateName] = true | |||
end | |||
end | end | ||
end | end | ||
| Line 220: | Line 222: | ||
local index = 1 | local index = 1 | ||
for templateName, _ in pairs(templateMap) do | for templateName, _ in pairs(templateMap) do | ||
templatesWithCampaigns[index] = templateName | |||
index = index + 1 | index = index + 1 | ||
end | end | ||
-- Sort the final combined list | -- Sort the final combined list | ||
table.sort( | table.sort(templatesWithCampaigns) | ||
return | return templatesWithCampaigns | ||
end | end | ||
-- Parse | -- Parse campaign template name to get base template and campaign info | ||
function p.parseVariantTemplate(templateName) | function p.parseVariantTemplate(templateName) | ||
if not templateName or templateName == "" then | if not templateName or templateName == "" then | ||
| Line 236: | Line 238: | ||
end | end | ||
-- Check if this is a | -- Check if this is a campaign combination by looking for the pattern "Template (Campaign Name)" | ||
if ConfigRepository. | if ConfigRepository.campaigns then | ||
for | for campaignId, campaign in pairs(ConfigRepository.campaigns) do | ||
if | local expectedName = " (" .. campaign.name .. ")" | ||
if templateName:sub(-#expectedName) == expectedName then | |||
local baseTemplateName = templateName:sub(1, -#expectedName - 1) | |||
-- Verify this is a valid combination | |||
if campaign.applicable_templates then | |||
for _, applicableTemplate in ipairs(campaign.applicable_templates) do | |||
if applicableTemplate == baseTemplateName then | |||
return { | |||
baseTemplate = baseTemplateName, | |||
variantKey = campaignId, | |||
variant = { | |||
name = templateName, | |||
campaign_template = campaign.json_config | |||
} | |||
} | |||
end | |||
end | end | ||
end | end | ||
| Line 253: | Line 263: | ||
end | end | ||
-- Not a | -- Not a campaign combination, return as base template | ||
return { | return { | ||
baseTemplate = templateName, | baseTemplate = templateName, | ||