10 - Cross-site includes (CSI)
nav_first.pngFirst: design:1
1 - Rate Module
Edited: 29 Apr 2012 00:01 by: James Kanjo
Comments: 21
nav_prev.pngPrevious: design:9
9 - CSS module for per-page styling
Edited: 11 Nov 2009 11:51 by: Steven Heynderickx
Comments: 13
Last: design:32
32 - Parenthood Module
Edited: 11 Nov 2009 21:47 by: Steven Heynderickx
Comments: 7
Next: design:11
11 - The Wikidot Data Model
Edited: 26 Oct 2009 01:12 by: leiger
Comments: 4

10 - Cross-site includes (CSI)
Created on 07 Sep 2009 19:52
By pieterh

rating: +4+x
This is the Redirect module that redirects the browser directly to the "http://projects.wikidot.com/thread:118" page.

Today we often copy/paste code between sites. This is inefficient for maintenance. I'd like to make a dynamic include function.

Invoking the include

[[include :sitename:category:page-name{number} argument="value"... /]] 
[[include :sitename:category:page-name/code/{number} argument="value"... /]]

Where sitename is either the name of the site (excluding '.wikidot.com') or a full wikidot subdomain name, or a custom domain.

The {number} selects a content section (similarly as for %%content{n}%%, allowing multiple sections in a page, included independently. The second form selects a code block, again numbered from 1 upwards.

We also use a new form for arguments, using a more standard 'var="value"' syntax. The value can contain quotes escaped as \". Arguments can also be specified within body of the include using the proposed consistent argument format:

[[include :sitename:category:page-name{number}]]
==== argument

Format of included page

The included page can be in one of three formats:

  • simple page (included fully)
  • sectioned page (each section can be included independently)
  • content mixed with code blocks (code blocks can be included independently)

Argument templating

The include page provides a templating mechanism using the same syntax as for _templates and ListPages. However the only symbols that is valid is: %%include{//name//}%% where 'name' is the name of the argument passed by the called.

All arguments can be given default values by using this syntax: %%arg{//name//}?//default//%%. This matches the proposed syntax for default values in ListPages and _templates.

Conditional templating

The include page can do conditional compile-time templating as follows:

[[if //condition//]] ... wiki text [[/if]]

The condition syntax is either of:

  • argument-name — true if the argument value is a non-empty string except "0" or "false" or "no"
  • argument-name operator value

Where operator is one of '=', '<>', '<', '<=', '>', '>=', 'in', 'ex'. 'in' and 'ex' take a list of values separated by spaces or commas.

Inline operation

The [[include]] tool, when properly formatted (with a closure), does not produce empty paragraphs before and after, so can be used inline with this syntax:

some text \
[[include sitename\category:page /]] \
some more text


This design takes into account the following Community documents:

Comments: 29

Add a New Comment