Include Part Of A Page Only

Posted by ErichSteinboeck on 01 Apr 2008 10:58, last edited by James Kanjo on 09 May 2010 05:50

Tags: conditional if include part

rating: +12+x

How To Include Only a Part of Another Page

Create your included page with “[!-- {$partn}” and “[!-- --]” markers (where n=1, 2, …) at the beginning and end of each block that you want to be able to selectively include or not.

That means: surround the first block of text, that may or may not be included with “{$part1}” and “[!----]”, the second block of text with “{$part2}” and “[!----]”, and so on. For example:

[!-- {$part1}
++++ This is Part 1

Four lines
# One
# Two
# Three
# Four
[!----]

[!-- {$part2}
++++ This is Part 2

Four more lines
* One
* Two
* Three
* Four
[!----]

Note that you may not use any Wikidot comment ([!----]) within the source code of any of your optional blocks.

On your including page, if you want to have the first block included, use e. g.

[[include name-of-included-page |part1= --] ]]

Or, if you want to have the first block excluded and the second block included, use

[[include name-of-included-page |part2= --] ]]

How it works

By specifying “|partn=--]” you are replacing the “{$partn}” marker in the included page with a closing Wikidot comment ([!----]). So the closing marker closes the starting Wikidot comment on the page, and allows the remaining content in the section to be rendered.

If you don't specify the marker with a Wikidot comment, then the entire marker's section is interpreted as a Wikidot comment, and as such the section will be “commented out” and not rendered on the page.

Example

Show first block, hide second

[[include inc:part-of-a-page-only part1= --] ]]

This is Part 1

Four lines

  1. One
  2. Two
  3. Three
  4. Four

Show second block, hide first

[[include inc:part-of-a-page-only part2= --] ]]

This is Part 2

Four more lines

  • One
  • Two
  • Three
  • Four

Show both blocks

[[include inc:part-of-a-page-only part1= --] | part2= --] ]]

This is Part 1

Four lines

  1. One
  2. Two
  3. Three
  4. Four

This is Part 2

Four more lines

  • One
  • Two
  • Three
  • Four

Show no blocks

[[include inc:part-of-a-page-only ]]

Links

A practical application of this concept can be found in Set Up An Infobox

Backlinks

Authors

ErichSteinboeckErichSteinboeck. Please visit his/her userPage.

James KanjoJames Kanjo. Please visit his/her userPage.


Related articles

Comments

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.