PmWiki /
Include Other Pagesauthors (intermediate) The SyntaxThe basic syntax is
The full syntax is
ParametersThe directive can have multiple Name parameters with or without anchors, and multiple template variable parameters. Named pages(:include PageName:) (:include Group.PageName:) (:include Page1 Page2 Group1.Page3 Group2.Page4:) Includes the entire text of another page into the current page. Multiple pages may be specified, but only the first available is included. You can use the above feature to display an error message if an include fails. Create a page, eg. Site.IncludeFailed containing the error message. You can use any page name. Then, in your include markup, append this page at the end of the page list: A slightly more complex approach is outlined at the talk page. #From#To anchors
Note: do not put whitespace between "#from" "#to" Note: text on the same line as a closing anchor but preceding the closing anchor will NOT be included in the text. Example Below: [[#start]] some text on the first line some text on the last line [[#end]] The above, when included via
Include from the first available of Page1, Page2 between the [[#from]] and [[#to]]
Include the first from the first available of Page1 (between the [[#from1]] and [[#to1]] ) or Page2 (between the [[#from2]] and [[#to2]] )
Lines=from..to
Include the first 10 lines, lines 5-10, or lines 5 and up from PageName. A "line" in this context refers to a line of source. Thus a line may be a paragraph that wraps over several lines on the screen, or a completely blank line.
Include the first five lines from the first available of Page1, Page2, or Page3. (To include lines from a list of pages, use a separate include for each.)
Self=
The parameter self can be 0 or 1 . It tells the include directive if it is allowed to include the current page. This is useful if PageName is a variable like {$Name} and you want to prevent the directive from including the current page.
Page text variables
Includes definition list values from an (optional) page as page text variables. These are defined using
Basepage=
Include PageName, but treat all relative links and page variables on PageName` as relative to BasePageName.
If Name: {$:Name} Address: {$:Address} then the directive (:include TemplateName basepage=PageName:)
will retrieve the contents of Basepage usageThe primary purpose of basepage is to allow the inclusion of pages in a way that mimics the 2.1.x behavior where page variables and links are interpreted relative to the currently displayed page. This is done with: (:include SomeOtherPage basepage='' :)
-or- (:include SomeOtherPage basepage={*$FullName} :)
It also allows GroupHeader and GroupFooter to have their page variables and links be relative to the currently displayed page (instead of GroupHeader and GroupFooter): ## PmWiki default Otherwise, using IncludeOtherPages inside of a GroupHeader would display 'GroupHeader' and not the name of the currently displayed page. The basepage= parameter is general enough that it can also be used as a templating engine, so that we can grab a template page containing variables that are then filled in with values from another page: (:include TemplatePage basepage=DataPage :)
And, of course, a single TemplatePage can actually contain multiple templates delimited by anchors, so that we end up with a syntax eerily similar[1] to pagelist-templates: So then TemplatePage can use a syntax like: [[#abc]] ...template stuff here... [[#abcend]] and it's possible to display TemplatePage as a template without it being interpreted... same as we do for Site.PageListTemplates. [1]Okay, maybe it's not so eerie, given that the pagelist template code actually uses the same function as (:include:) to grab its templates. But it's still a useful parallel.
Specifying variables as parameters: Use sections as templatesYou can also specify variable values inline with the include statement, and refer to the variables in the template using the (:include TemplatePage variable1="value" variable2="value2":)
This assumes that a site has For example, on my included page ("template") I might have this:
Then, including that section above (that section is available via the section
If a value contains spaces, quote it:
See also Specific markup
The purpose of See this thread and this thread for more info.
Parameter ReferencesAny parameters supplied to an include statement (whether they are keywords or not) are accessible inside the included page as a special Notes
Styling NoteBy default, Included pages or lines cannot be distinguished from other text on the page. To provide a visual indication that this text is special, you can apply Wiki Styles. For example:
Notes about use with conditional markupThe (:if some condition:)(:include SomePage#section:)(:if:)
But (:if some condition:)[[#section]]...[[#sectionend]](:ifend:)
When testing variables in included pages the context of the page (source or target) can be useful. See special references for details. See Also
FAQWhat's the maximum number of includes that can exist in a page? My site seems to stop including after 48 includes. ( $MaxIncludes )
By default, PmWiki places a limit of 50 include directives for any given page, to prevent runaway infinite loops and other situations that might eat up server resources. (Two of these are GroupHeader and GroupFooter.) The limit can be modified by the wiki administrator via the Is there any way to include from a group of pages without specifying by exact name, e.g. between Anchor X and Y from all pages named IFClass-* ? This can be achieved using page lists. There appears to be a viewing issue when the included page contains the (:title:) directive. In a default installation, the last title in the page overrides previous ones so you can place your (:title :) directive at the bottom of the page, after any includes. See also How to test to see if the page is part of another page?
Is there any way to include (chapters of) pages which are protected (authuser.php)? You can achieve this the other way around: have the public sections in a public page (passwdread=@nopass or @_site_read) and include those into both the protected page, and the public page. Note that it is strongly recommended to NOT hide sensitive content inside a conditional in an unprotected page. This page may have a more recent version on pmwiki.org: PmWiki:IncludeOtherPages, and a talk page: PmWiki:IncludeOtherPages-Talk. |