# Include Other Pages

authors (intermediate)

The (:include:) directive makes it possible to insert (or "transclude") the contents of other pages into the current wiki page. All of the include directives below perform a straight text inclusion. In particular, any page links in the included text are assumed to link to pages in the current group if not otherwise qualified.

## Syntax

The basic syntax is

• (:include :)
with pagename includes the full page from the same group.

{Group/PageName$:Var} Includes definition list values from an (optional) page as page text variables. These are defined using a definition list (:item:description), simple colon delimiter (item:description), or special markup ((:item:description:)). ### Basepage= (:include PageName basepage=BasePageName:) Include , but treat all relative links and page variables on  as relative to . If basepage= is provided all relative links and page variables are interpreted relative to basepage. So, if one creates TemplateName as Name: {$:Name}
Address: {$:Address} then the directive (:include TemplateName basepage=PageName:) will retrieve the contents of TemplateName, treating any page variables and links as being relative to PageName. In particular, the values for {$:Name} and {$:Address} will be taken from PageName, but things like {$Title} and {$LastModifiedBy} would also work here. #### Basepage usage The 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 $GroupHeaderFmt setting $GroupHeaderFmt =
'(:include {$Group}.GroupHeader self=0 basepage={*$FullName}:)(:nl:)';


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 can actually contain multiple templates delimited by anchors, so that we end up with a syntax eerily similar[1] to pagelist-templates:

    (:include TemplatePage#abc basepage=DataPage :)


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.

## Notes

• You can also say (:include My/Page#myanchor lines=4:) which starts from, and includes, the line with the anchor [[#myanchor]] for four lines.

### Styling Note

By 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:

 %define=leftborder border-left="2px solid #88f" margin-left="2px" padding="1px 0 3px 10px"% What is PmWiki? >>leftborder<< (:include PmWiki.PmWiki lines=1..4:) >><< ''Have a very nice day!''  What is PmWiki? ! Pmwiki PmWiki is a wiki-based system for collaborative creation and maintenance of websites. PmWiki pages look and act like normal web pages, except they have an "Edit" link that makes it easy to modify existing pages and add new pages into the website, using basic editing rules. You do not need to know or use any HTML or CSS. Page editing can be left open to the public or restricted to small groups of authors. Have a very nice day!

### Notes about use with conditional markup

The (:include ...:) markup is processed after conditional markup is evaluated.
Therefor you can include a page or page section as part of a condition, like

(:if some condition:)(:include SomePage#section:)(:if:) 

But (:include SomePage#section:) doesn't look to see if [[#section]] is part of a conditional, like

(:if some condition:)[[#section]]...[[#sectionend]](:ifend:)

(:include SomePage#section:) will ignore such a condition.

When testing variables in included pages the context of the page (source or target) can be useful. See special references for details.

## FAQ

What'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 $MaxIncludes variable.

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 -* ?

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 $EnablePageTitlePriority. How to test to see if the page is part of another page?  (:if ! name {$FullName}:) %comment% name of this page is not the same as the page this text was sourced from ->[[{\$FullName}#anchor | more ...]] (:ifend:) `

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.