Include Part Of A Page Only (Tricky Version)

Posted by ErichSteinboeck on 02 Apr 2008 22:55, last edited by James Kanjo on 07 Dec 2014 01:52

Tags: conditional if include part

rating: +13+x

How To Include Only a Part of Another Page (Tricky Version)

This is a more sophisticated version of How To Include Only a Part of Another Page as it allows you to use a page

  1. both on its own (i. e. not included in another page), and
  2. be able to omit certain parts of it when it is included in another page.

Step by Step

Create your included (and/or standalone) page by adding the following “markers” at the beginning and at the end of each optional block of text (that you want to be able to either include or omit):

  • begin marker: [!--{$partn}--]@@@@ (where n=1, 2, …)
  • end marker: [!-- --]

That means: surround the first optional block of text with [!--{$part1}--]@@@@ and [!-- --], surround the second optional block of text with [!--{$part2}--]@@@@ and [!-- --], and so on.

Note:
1. Do not use any Wikidot comment ([!-- --]) within the source code of any of your optional blocks
2. The Wikidot syntax does not allow the begin marker in certain positions, like between the [[table]] and the following [[row]] tag, although it is acceptable to use it between an [[/row]] and a [[row]] tag.

On your including page, specify partn=@@ for each optional block that should be omitted, e. g.

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

All blocks not specified in the [[include]] will be included by default.

How it works

By specifying partn=@@ you are

  • replacing the begin marker [!--{$partn}--]@@@@ with [!--@@--]@@@@.
  • The pair of underlined @@ convert the closing part (--]) of the Wikidot comment into raw text, that isn't interpreted.
  • As such it leaves the opening part of a Wikidot comment, commenting out any following block of text.

If you do not specifying partn=@@

  • the begin marker [!--{$partn}--]@@ is ignored because the first part is a simple comment and second part (the four @'s) is the empty string converted to raw text, and
  • the end marker [!-- --] is again just a comment.

Examples

Example Include Page

Some text that's always there.

[!--{$part1}--]@@@@
The first block of text that is optional.

[!-- --]
[!--{$part2}--]@@@@
Another optional block of text

[!-- --]
[[table]]
[[row]][[cell]]Name:[[/cell]][[cell]]Its name[[/cell]][[/row]]
[!--{$part3}--]@@@@
[[row]]
[[cell]]Option:[[/cell]]
[[cell]]an optional row in a table[[/cell]]
[[/row]]
[!-- --]
[[row]][[cell]]Player:[[/cell]][[cell]]Any[[/cell]][[/row]]
[[/table]]

Example Included Page

What you type … What you get …
 [[include inc-page]]
Some text that's always there.

The first block of text that is optional.

Another optional block of text
Name: Its name
Option: an optional row in a table
Player: Any
 [[include inc-page part1=@@]]
Some text that's always there.

Another optional block of text
Name: Its name
Option: an optional row in a table
Player: Any
 [[include inc-page part2=@@]]
Some text that's always there.

The first block of text that is optional.
Name: Its name
Option: an optional row in a table
Player: Any
 [[include inc-page part3=@@]]
Some text that's always there.

The first block of text that is optional.

Another optional block of text
Name: Its name
Player: Any
 [[include inc-page part1=@@ | part3=@@]]
Some text that's always there.

Another optional block of text
Name: Its name
Player: Any

Links

This is an extension of the ideas presented in Include Part of a Page Only

Backlinks

Author

ErichSteinboeckErichSteinboeck. 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.