Include Variables with Special Characters

Posted by gerdami on 20 Nov 2008 11:32, last edited by GoVegan on 09 May 2010 05:51

: include special-character variable

rating: +5

The [[include …]] tag allows to specify include variables — placeholders, together with arbitrary text strings (the include variable's value) that will replace them on the included page.

Although, in general, include variable values may contain any character, some characters may be challenging to enter.

Closing Brackets

If you follow the inc example in the Wikidot syntax documentation

[[include pagename var1=value1 | number_books = 43 | title=Best Wiki Ever
| variable_name = just a variable
| variableName = another variable
]]

and try to add an include variable whose value ends in two (or more) closing brackets (like [[size smaller]]Text to display[[/size]]) with this code

[[include pagename var1=value1 | number_books = 43 | title=Best Wiki Ever
| variable_name = just a variable
| variableName = another variable
| text = [[size smaller]]Text to display[[/size]]
]]

it will fail. Consecutive closing brackets at the very end of an include statement's line will end the include.

Most of the time you can avoid having consecutive closing brackets at the end of a line, by moving the pipe (“|”) symbols (that are separating adjacent include variables) to the end of the line. In the case of the last (or only ) include variable in an include, you can either

  • move the two closing brackets (that end the include) to the end of the line, or
  • add a pipe (“|”) symbol after the last (or only) include variable (additional pipe symbols do not hurt)

Thus a working code would look like this:

[[include pagename var1=value1 | number_books = 43 | title=Best Wiki Ever |
variable_name = just a variable |
variableName = another variable |
text = [[size smaller]]Text to display[[/size]] ]]

Cannot Move Pipe Symbol to Line End

In case you cannot move a pipe symbol to the end of the line, because the Wikidot syntax requires you to write a tag on its own line ([[include …]] is an example) here's a workaround.

Let's assume you want the value of an include variable to be the following (the value itself should contain another [[include …]]):

Text before include
[[include boilerplate]]
Text after include

Coding

[[include pagename
text=Text before include
[[include boilerplate]]
Text after include
]]

would fail (as the [[include boilerplate]]'s closing brackets end the outer include). Instead you might use:

[[include pagename
text=Text before include
[[include boilerplate{$br}]
Text after include |
br=]
]]

Pipe Symbol

An even bigger challenge poses the pipe symbol (“|”).

If you try to add an include variable whose value contains an internal link (like [[[page|link text to show]]]) with the code

[[include pagename var1=value1 | number_books = 43 | title=Best Wiki Ever
| variable_name = just a variable
| variableName = another variable
| link = [[[page|link text to show]]]
]]


it will again fail. The pipe symbol within the internal link is interpreted as an include variable separator so that the value of “link” becomes [[[page only.

There is no general solution how to include a pipe symbol in an include variable value, but for special cases there are workarounds.

Rewrite Internal Link

To avoid having to use a pipe symbol in an internal link, rewrite the link in the alternate format.

[/page link text to show]

Note that for the alternate format the link text is mandatory, whereas for the standard internal link format the link text is optional, so for some cases this workaround introduces an incompatibility.
Include a Page with Pipe Symbol

Here's another idea:

[[include pagename
link=[[[page
[[include :csi:pipe]{$br} |
link text to show]]] |
br=]
]]

which includes this page (containing a single “|” symbol)

Backlinks

Author

ErichSteinboeck ErichSteinboeck . Please visit his/her userPage.


Related articles

Comments

jbnv jbnv 05 Jan 2009 21:03

The matter with the pipe character is a substantial bug that needs to be fixed.

by jbnv jbnv , 05 Jan 2009 21:03
A simpler workaround
tahuong tahuong 19 Jul 2009 10:33

Why dont you just put the special character in the included page itself, not in the variable value?

Instead of

[[include pagename var1=value1 | number_books = 43 | title=Best Wiki Ever
| variable_name = just a variable
| variableName = another variable
| link = [[[page|link text to show]]]
]]

you just put in your included page

 I want this link to change upon my whim: [[[{$page}|{$linktext}]]]

and the include syntax is:

[[include pagename var1=value1 | number_books = 43 | title=Best Wiki Ever
| variable_name = just a variable
| variableName = another variable
| page = someurl
| linktext = flowerywords
]]

Admittedly it will cost you another variable in this case, but it's handy in many other cases. I've tested with links (page only, link text only, or both), user (by [[*user {$author}]]), size with all kinds of unit ([[size {$size}]]Look, Im a resizable text.[[/size]]) and all work well.

This will reduce the flexibility of the value, but on the second hand, if you already have a strict formula, I have the notion that to edit one included page will avoid mistakes better than to repeatedly type [[[]]] in pages with includes..

Or I have overlooked some profound things being a newbie? @_@

by tahuong tahuong , 19 Jul 2009 10:33
Re: A simpler workaround
GoVegan GoVegan 19 Jul 2009 15:39

You seemed to have grasped onto the syntax really well for a newbie! Well done!

The thing I don't like about your method is that you can't set the link inline within an existing variable (as you can with the method documented on this page). But indeed it is a far simpler solutions to the problem at hand.

by GoVegan GoVegan , 19 Jul 2009 15:39
North North 19 Jul 2009 17:04

The easiest way to have multiple closing brackets at the end of the line in an include is to add an extra space after the brackets. I will note the space with _ in the following example.

[[include pagename
|var1=[[span]]value1[[/span]]_
|var2=[[[category:page]]]_
]]

The code above is tested and works.

I only needed the pipe for a couple of links. I fixed this by using the regular one bracket link.

by North North , 19 Jul 2009 17:04
Re: Trailing blanks
ErichSteinboeck ErichSteinboeck 19 Jul 2009 19:56

> add an extra space after the brackets

North, I'd rather discourage use of trailing blanks.

  • For one, when re-visiting / re-using the code, one most easily forgets about the meaningful trailing blanks and will spend hours as to why this codes works there, but not here, and

  • second, there is a good chance that a future change to the parser will ignore trailing blanks — see the discussion in thread Default Content in Live Templates not working
by ErichSteinboeck ErichSteinboeck , 19 Jul 2009 19:56
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /