Posted by ErichSteinboeck on 01 Apr 2008 10:58, last edited by GoVegan on 09 May 2010 05:50
Tags: conditional if include part
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 1Four lines
|
Show second block, hide first
[[include inc:part-of-a-page-only part2= --] ]] |
This is Part 2Four more lines
|
Show both blocks
[[include inc:part-of-a-page-only part1= --] | part2= --] ]] |
This is Part 1Four lines
This is Part 2Four more lines
|
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
ErichSteinboeck. Please visit his/her userPage.
James Kanjo. Please visit his/her userPage.
I updated the code of this page using a method that came to me in a dream last night (indeed, I am a tragic case who dreams solutions to programming problems).
Now the code on the include page contains section markers like so:
In this way, to include a page, the user only needs to specify the section that they want to include. This will show only section two:
[[include page |section2=--] ]]
Previously, you had to specify each and every section, whether you wanted to display them or not. This will show only section two:
[[include page |section1=[!-- | section2=[!-- --] ]]
So now the process is so much simpler! Please remember to thank my subconscious, as I personally made no conscious effort to refine this code.
Very useful. Thanks… uh, subconscious of James Kanjo…. :S
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
He's trying to say something back… but it's all mumble-jumble to me at the moment. I'll get back to you tomorrow morning?
Why are you listed as a contributor at the bottom of the page? Are you trying to steal credit? :O
Maybe that is what your subconscious is complaining about, not being properly recognised for their contribution? ;-)
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me
James Subconscious can't be a pro account, because he can't pay. His only job is to think of ideas for James, and he doesn't get paid well.
This is neat. I used to get solutions in my sleep too, but I learned to day dream :-)
Portfolio
Well done, James… Errrr… James' subconsciousness…
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
Thanks James' subconsciousness.
Is your subconsciousness as good as debates as you, James?
I´d like to see origin page im including. I know that this solution (http://community.wikidot.com/howto:include-part-of-a-page-only-tricky-version) can do it, but there is big differece i dont like (that i have to specify what i dont want to include instead of what i want to include).