Posted by ErichSteinboeck on 02 Apr 2008 22:55, last edited by GoVegan on 07 Dec 2014 01:52
Tags: conditional if include part
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
- both on its own (i. e. not included in another page), and
- 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 … | ||||||
|
Some text that's always there.
|
||||||
|
Some text that's always there.
|
||||||
|
Some text that's always there.
|
||||||
|
Some text that's always there.
|
||||||
|
Some text that's always there.
|
Links
This is an extension of the ideas presented in Include Part of a Page Only
Backlinks
Author
ErichSteinboeck. Please visit his/her userPage.
This one is simpler than this one, but… Wouldn't it be simpler to put in include module the part that IS included, and not the part that is NOT included? Usually, there are less parts (and most of times only one), that you want to include, and many others that you don't want to be seen? Besides, it is more logical to put in the include module what you want to include, and not what you want to exclude….
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
Yes, that would be great!
Today I was using your old method:
When I found that the empty <a></a> tags being created were breaking my layout in IE6.
So I set out to get rid of this, and this is what I concluded:
[!--{$part1}--]@@@@
The first block of text that is optional.
[!--{$part1}--]
Because this in affect would interpret like so:
[!--@@--]@@@@
The first block of text that is optional.
[!--@@--]
Everything between the Wikidot comments is interpreted literally.
Then I come over here to update this page, and what do I find? You've actually updated this almost a year ago, with an even more ingenious method !
[!--@@--]@@@@
The first block of text that is optional.
[!-- --]
The start of the second comment is treated as part of the first comment… brilliant !
Hi, thanks for this how-to, it really helped me.
I was wondering if there is a way to include some part of a page from another wikidot site i own.
Thanks for answer!
This can be done using CSIs. It is essentially the same as an include, except you can include from other sites.
The syntax is only slightly different:
Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me