This page is a translated version of the page Module:Transcluder/doc and the translation is 20% complete.

This module is a general-purpose transclusion engine, able to transclude any part of any page and with many options that normal transclusion doesn't provide.

用法

模块

模块的主入口是get方法。

  • get( 'Title' ) — 获取请求的页面(与正常的嵌入包含有完全相同的结果)
  • get( 'Title#' ) — 获取请求页面的序言章节
  • get( 'Title#Section' ) — 获取请求的章节或‎<section>标签(包括所有子章节)

‎<noinclude> and ‎<onlyinclude> tags are handled the usual way and there's also an optional second parameter to exclude various elements from the result:

  • get( 'Title#Section', { files = 0 } ) — 排除所有文件
  • get( 'Title#Section', { files = 1 } ) — 排除除第一个文件外的所有文件
  • get( 'Title#Section', { files = 2 } ) — 排除除第二个文件外的所有文件
  • get( 'Title#Section', { files = '1,2' } )Exclude all files except the first and second
  • get( 'Title#Section', { files = '1-3' } )Exclude all files except the first, second and third
  • get( 'Title#Section', { files = '1,3-5' } )Exclude all files except the first, third, fourth and fifth
  • get( 'Title#Section', { files = -2 } )Exclude the second file
  • get( 'Title#Section', { files = '-2,3' } )Exclude the second and third files
  • get( 'Title#Section', { files = '-1,3-5' } )Exclude the first, third, fourth and fifth files
  • get( 'Title#Section', { files = 'A.png' } )Exclude all files except A.png
  • get( 'Title#Section', { files = '-A.png' } )Exclude A.png
  • get( 'Title#Section', { files = 'A.png, B.jpg, C.gif' } )Exclude all files except A.png, B.jpg and C.gif
  • get( 'Title#Section', { files = '-A.png, B.jpg, C.gif' } )Exclude A.png, B.jpg and C.gif
  • get( 'Title#Section', { files = { [1] = true, [3] = true } } )Exclude all files except the first and third
  • get( 'Title#Section', { files = { [1] = false, [3] = false } } )Exclude the first and third files
  • get( 'Title#Section', { files = { ['A.png'] = false, ['B.jpg'] = false } } )Exclude A.png and B.jpg
  • get( 'Title#Section', { files = '.+%.png' } )Exclude all files except PNG files (see Lua patterns)
  • get( 'Title#Section', { files = '-.+%.png' } )Exclude all PNG files

The very same syntax can be used to exclude many other elements:

  • get( 'Title#Section', { sections = 0 } )Exclude all subsections
  • get( 'Title#Section', { sections = 'History, Causes' } )Exclude all subsections except 'History' and 'Causes'
  • get( 'Title#Section', { lists = 1 } )Exclude all lists except the first
  • get( 'Title#Section', { tables = 'stats' } )Exclude all tables except the one with id 'stats'
  • get( 'Title#Section', { paragraphs = '1-3' } )Exclude all paragraphs except the first, second and third
  • get( 'Title#Section', { references = 0 } )Exclude all references
  • get( 'Title#Section', { categories = '0' } )Exclude all categories
  • get( 'Title#Section', { templates = '-.+infobox' } )Exclude infobox templates
  • get( 'Title#Section', { parameters = 'image' } )Exclude all parameters from all templates except the one named 'image'

Options can be combined at will. For example:

  • get( 'Title#Section', { sections = 0, files = 1, paragraphs = '1-3' } )Exclude all subsections, all files except the first, and all paragraphs except the first three

You can also get only some elements like so:

  • get( 'Title#Section', { only = 'files' } )Get only the files
  • get( 'Title#Section', { only = 'lists', lists = 1 } )Get only the first list
  • get( 'Title#Section', { only = 'tables', tables = 'stats' } )Get only the table with id 'stats'
  • get( 'Title#Section', { only = 'paragraphs', paragraphs = '1,3-5' } )Get only the first, third, fourth and fifth paragraph
  • get( 'Title#Section', { only = 'templates', templates = 'Infobox' } )Get only the infobox
  • get( 'Title#Section', { only = 'parameters', parameters = 'abstract', references = 0 } )Get only the parameter called 'abstract' and remove all the references from it

The output can be further modified with a few special options:

  • get( 'Title#Section', { noFollow = true } ) — 不要跟从重定向
  • get( 'Title#Section', { linkBold = true } )Link the bold title or synonym near the start of the text
  • get( 'Title#Section', { noBold = true } ) — 删除加粗文字
  • get( 'Title#Section', { noComments = true } )Remove comments
  • get( 'Title#Section', { noLinks = true } )Remove all links
  • get( 'Title#Section', { noSelfLinks = true } ) — 删除自我链接
  • get( 'Title#Section', { noNonFreeFiles = true } )Remove non-free files (currently identified by having the words 'non-free' in their local description or at Commons)
  • get( 'Title#Section', { noBehaviorSwitches = true } )Remove behavior switches such as __NOTOC__
  • get( 'Title#Section', { fixReferences = true } )Prefix reference names with 'Title ' to avoid name conflicts when transcluding and rescue references defined outside the requested section to avoid undefined reference errors

Besides the get method, the module exposes several other methods to get specific parts of the wikitext. This allows other modules to combine elements in more advanced ways.

模板

The main entry point for templates is the main method. It's essentially a wrapper of the get method to make it usable for templates.

See the documentation of the get method for more details and options.

  • {{#invoke:Transcluder|main|Title}}Transclude the requested page
  • {{#invoke:Transcluder|main|Title#}}Transclude the lead section of the requested page
  • {{#invoke:Transcluder|main|Title#Section}}Transclude the requested section or ‎<section> tag (includes any subsections)
  • {{#invoke:Transcluder|main|Title#Section|sections=0}}Transclude the requested section, excluding subsections
  • {{#invoke:Transcluder|main|Title|only=files|files=1}}Transclude only the first file of the page
  • {{#invoke:Transcluder|main|Title#Section|only=tables|tables=2}}Transclude only the second table of the requested section
  • {{#invoke:Transcluder|main|Title#|only=paragraphs|linkBold=yes}}Transclude only the paragraphs of the lead section and link the bold text

參見