Différences entre les versions de « Module:Navigation »

De Encyclopédie francophone de la Roue du Temps
Aller à la navigation Aller à la recherche
(Page créée avec « local p = {} function p.build(frame) local palette = mw.html.create('table'):addClass('mw-palette') if frame.args['classes'] ~= nil and frame.args['classes']… »)
 
 
Ligne 2 : Ligne 2 :


function p.build(frame)
function p.build(frame)
     local palette = mw.html.create('table'):addClass('mw-palette')
     local navigation = mw.html.create('table'):addClass('mw-navigation')
      
      
     if frame.args['classes'] ~= nil and frame.args['classes'] ~= '' then
     if frame.args['classes'] ~= nil and frame.args['classes'] ~= '' then
       palette:addClass(frame.args['classes'])
       navigation:addClass(frame.args['classes'])
     end
     end
      
      
     frame.args['classes'] = nil
     frame.args['classes'] = nil
      
      
     -- Palette's title
     -- Navigation's title
     if frame.args['titre'] ~= nil and frame.args['titre'] ~= '' then
     if frame.args['titre'] ~= nil and frame.args['titre'] ~= '' then
         palette
         navigation
             :tag('tr')
             :tag('tr')
             :tag('th')
             :tag('th')
             :addClass('mw-palette-title')
             :addClass('mw-title')
             :attr('colspan', '2')
             :attr('colspan', '2')
             :wikitext(frame.args['titre'])
             :wikitext(frame.args['titre'])
Ligne 22 : Ligne 22 :
     frame.args['titre'] = nil
     frame.args['titre'] = nil
      
      
     -- Palette's body
     -- Navigation's body
     local section
     local section
      
      
Ligne 31 : Ligne 31 :
         else
         else
             -- Print section name and values
             -- Print section name and values
             palette
             navigation
                 :tag('tr')
                 :tag('tr')
                 :tag('th'):wikitext(section):done()
                 :tag('th'):wikitext(section):done()
Ligne 38 : Ligne 38 :
     end
     end
      
      
     return tostring(palette)
     return tostring(navigation)
end
end


return p
return p

Version actuelle datée du 2 décembre 2021 à 21:55

Le module Module:Navigation facilite la création de palette de navigation.

Syntaxe

{{#invoke:Navigation|build
| classes = Classes optionnelles
| titre = Titre optionnel de la palette
| Titre de la première section
| Contenu de la première section
| ...
| Titre de la dernière section
| Contenu de la dernière section
}}

Exemples

Navigation simple

{{#invoke:Navigation|build
| classes = Classes optionnelles
| titre = Titre
| Section #1
| Contenu #1
| Section #2
| Contenu #2
| Section #3
| Contenu #3
}}
Titre
Section #1 Contenu #1
Section #2 Contenu #2
Section #3 Contenu #3
Section #4 Contenu #4

Nvigations imbriquées

{{#invoke:Navigation|build
| titre = Titre
| Section #1
| {{#invoke:Navigation|build
  | Section #1.1
  | Contenu #1.1
  | Section #1.2
  | Contenu #1.2
  }}
| Section #2
| {{#invoke:Navigation|build
  | titre = Titre imbriquée
  | Section #1.1
  | Contenu #1.1
  | Section #2.2
  | Contenu #2.2
  }}
| Section #3
| Contenu #3
| Section #4
| Contenu #4
}}
Titre
Section #1
Section #1.1 Contenu #1.1
Section #1.2 Contenu #1.2
Section #2
Titre imbriquée
Section #1.1 Contenu #1.1
Section #2.2 Contenu #2.2
Section #3 Contenu #3
Section #4 Contenu #4
local p = {}

function p.build(frame)
    local navigation = mw.html.create('table'):addClass('mw-navigation')
    
    if frame.args['classes'] ~= nil and frame.args['classes'] ~= '' then
       navigation:addClass(frame.args['classes'])
    end
    
    frame.args['classes'] = nil
    
    -- Navigation's title
    if frame.args['titre'] ~= nil and frame.args['titre'] ~= '' then
        navigation
            :tag('tr')
            :tag('th')
            :addClass('mw-title')
            :attr('colspan', '2')
            :wikitext(frame.args['titre'])
    end
    
    frame.args['titre'] = nil
    
    -- Navigation's body
    local section
    
    for index, value in ipairs(frame.args) do
        if 1 == index % 2 then
            -- Memorize section name
            section = value
        else
            -- Print section name and values
            navigation
                :tag('tr')
                :tag('th'):wikitext(section):done()
                :tag('td'):wikitext(value)
        end
    end
    
    return tostring(navigation)
end

return p