Gabrys wrote on 24 Mar 2010 13:53
This is to reply to James' question about includes with variables.
First of all what kind of syntaxes we want to support:
[[include page | variable1=value1]]
Simple include.
[[include page | %%content%%]]
We pass all the content as variables section. It needs to be in form of: "variable = value | variable = value | …"
[[include page | variable1=%%content%%]]
We pass all the content as ONE variable, so that in include, there is %%content%% available as ${variable1}.
One small note: I don't really believe supporting passing %%content%% as multiple variables makes any sense. This might be needed to overcome some limitations. I'm just guessing. Please tell me why we need to support this.
So let's get started.
First of all we need the following tags:
- <include> — [[include]] recognized, page source waits to be injected there.
- <variable> — variable passed to include
- <include-variable> — this is what ${variable} is converted to in included page
- <template-symbol> — a template symbol, for example %%content%%
Let the parser play :-)
<wiki>
[[include page | variable1=value1]]
</wiki>
Needs to be:
<include>
<page-name>page</page-name>
<variables>
<variable>
<name>variable1</name>
<value>value1</value>
</variable>
</variables>
</include>
Second example. This time we will expose more passes of parsing:
<wiki>
[[include page | %%content%%]]
</wiki>
<include>
<page-name>page</page-name>
<variables>
<wiki>%%content%%</wiki>
</variables>
</include>
<include>
<page-name>page</page-name>
<variables>
<template-symbol>content</template-symbol>
</variables>
</include>
Suppose %%content%% is variable2=value2 | variable3=value3
<include>
<page-name>page</page-name>
<variables>
<wiki>variable2=value2 | variable3=value3</wiki>
</variables>
</include>
<include>
<page-name>page</page-name>
<variables>
<variable>
<name>variable2</name>
<value><wiki>value2</wiki></value>
</variable>
<variable>
<name>variable3</name>
<value><wiki>value3</wiki></value>
</variable>
</variables>
</include>
<include>
<page-name>page</page-name>
<variables>
<variable>
<name>variable2</name>
<value>value2</value>
</variable>
<variable>
<name>variable3</name>
<value>value3</value>
</variable>
</variables>
</include>
Nice. Let's go further:
<wiki>
[[include page | variable1=%%content%%]]
</wiki>
<include>
<pagename>page</pagename>
<variables>
<wiki>variable1=%%content%%</wiki>
</variables>
</include>
<include>
<pagename>page</pagename>
<variables>
<variable>
<name>variable1</name>
<value><wiki>%%content%%</wiki></value>
<variable>
</variables>
</include>
<include>
<pagename>page</pagename>
<variables>
<variable>
<name>variable1</name>
<value><template-symbol>content</template-symbol></value>
<variable>
</variables>
</include>
<include>
<pagename>page</pagename>
<variables>
<variable>
<name>variable1</name>
<value><wiki>variable2=value2 | variable3=value3</wiki></value>
<variable>
</variables>
</include>
All content passed as one variable. This works nicely :)
Note:
If you look closely at what happens, we always defer symbol replacement, so we can match different rules that don't match after symbols are replaced (variable1=%%content%% — we want all %%content%% even if %%content%% has "|other-variable=something-else" in it!). But some rules may match only after replacement (like [[include page | %%content%%]]. So we need to apply wiki-syntax rules after symbol replacement as well. The trick is to make the applying rules safe on text that was already matched (so we can apply rules many many times). The XML-like notion is the answer to this.
(In this and previous examples, XML is only an example coding, that's easy to understand for most of Wikidot users. Actual coding as well as some internal names/tags may be totally different, but how it works will be the same.)
[[include page | %%form_data{fieldname}%%]]
Disadvantages for this methode:
will this become available? Or should I wait for the page-selector inside [[module listpages]]? So I can get the same result with this:
[[module listpages select="page:name"]]
%%form_data{fieldname}%%
[[/module]]
Disadvantages for this methode:
Could the include have an attribute linebreak="true/false" ?
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
Sure! %%form_data{fieldname}%% is nothing more than %%content%% :).
Well, it is, but in the scope of parsing it's the same: a symbol to replace with some real-page value :-)
Piotr Gabryjeluk
visit my blog
But I altered some stuff…
Could you comment again…
I understand the part of %%Form_data{fieldname}%% No comment needed
any comment on atrribute linebreak on/off?
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
Steven, I deeply believe line breaks should be solved more nicely. For example:
This is in-line include, it won't add any line breaks, before nor after itself (given there are no line breaks inside the include).
Now, include is on its own line, so there will be a line break after it.
In fact the include itself should never control line breaks. The problem now is that you need to put the include on it's own line which implies the creation of line breaks. This could be one of the nicest benefits of new parser design — there may be includes all over the line.
Piotr Gabryjeluk
visit my blog