راهنما:استنتاج جزئی

از ویکی‌کد، دانشنامهٔ برنامه‌نویسی
پرش به ناوبری پرش به جستجو

https://www.mediawiki.org/wiki/Transclusion

Partial transclusion

By using "<tvar name=noincl>noinclude</tvar>", "<tvar name=onlyincl>onlyinclude</tvar>" and "<tvar name=inclonly>includeonly</tvar>" markup, it is possible to transclude part of a page rather than all of it. Such partial transclusions can also be achieved by transcluding from other pages such as subpages. It is often desirable not to transclude some information, such as template documentation and categories.


Examples of when to use full versus partial transclusion

Use full transclusion when you want to include the full content of a source page in a target page. For example, you could include the full content of a page about apples in a page about tree fruits. Use partial transclusion when you only want to include part of a source page in a target page. For example, you could include only information about Granny Smith apples from a page about apples in a page about ingredients commonly used in baking.


Partial transclusion markup

  • noinclude - The markup <tvar name=1><noinclude>...</noinclude></tvar> means that the text between the tags is visible exclusively on the source page and cannot be transcluded onto another page. This is useful for template documentation and categories.
  • includeonly - The markup <tvar name=1><includeonly>...</includeonly></tvar> means that the text between the tags will be hidden on the source page and visible only when transcluded onto a different page. This can be useful, for example, for adding categories to pages transcluding a template, without adding the template itself to these categories.
  • onlyinclude - The markup <tvar name=1><onlyinclude>...</onlyinclude></tvar> means that the text between the tags will be visible on the source page and visible when transcluded onto a different page. This is the most subtle of the partial transclusion tags because it often overrules the others. If there is at least one pair of "<tvar name=1>onlyinclude</tvar>" tags on a page, then whenever this page is transcluded, it is only the material within the "<tvar name=2>onlyinclude</tvar>" tags that is transcluded. There can be several such "<tvar name=1>onlyinclude</tvar>" sections on a page. This can be useful, for example, to repeat a small part of one page on a second one: just surround the small part by <tvar name=1>onlyinclude</tvar> tags, and transclude it onto the second page.
<noinclude>, <includeonly>, and <onlyinclude> behave differently inside <nowiki> tags. nowiki tags enable escaping special markup, and does this for <noinclude> and <includeonly> tags. However, <onlyinclude> tags within <nowiki> tags produces only the content inside the <onlyinclude> tag.
Markup Output when transcluded
<nowiki><noinclude> My content </noinclude></nowiki> <noinclude> My content </noinclude>
<nowiki><includeonly> My content </includeonly></nowiki> <includeonly> My content </includeonly>
<nowiki><onlyinclude>My content</onlyinclude></nowiki> My content

You can nest all three transclusion types within each other, which enables you to refine exactly what content is displayed on the current page and is visible on transcluded pages.


Subpages

You can cut and paste the text to be transcluded into a subpage, then use the name of the subpage in the transclusion template. This approach can be used only where subpages are enabled; for example, on the English Wikipedia, subpages can be used only from User, Talk or Wikipedia pages; currently, subpages cannot be created from main article pages.

Example: you want to discuss the deletion and redirecting of Pussycat to Cat. First, create the subpage Talk:Pussycat/Let's delete Pussycat!, write your comment into it, then transclude it in Talk:Pussycat and Talk:Cat using the template {{Talk:Pussycat/Let's delete Pussycat!}}. Comments posted in either talk page will be shown in both.

Special pages

See also:w:Wikipedia:Transclusion#Special pages and <tvar name=1>Manual:$wgAllowSpecialInclusion </tvar>

Some pages on Special:Specialpages can be transcluded, such as Special:AllPages, Special:PrefixIndex, Special:NewFiles, Special:NewPages, Special:RecentChanges and Special:RecentChangesLinked.

Sample: {{Special:Newpages/3}} gives 3 new pages.

[[<tvar name=manparamindex>Special:MyLanguage/Manual:Parameters to index.php</tvar>|URL parameters]] can be given like template parameters, e. g. {{Special:RecentChanges|namespace=10|limit=5}}.