INCLUDE Page Shortcode
docs/plugins/plugin.jacshortcode.include
/*
Title: INCLUDE Page Shortcode
description: Include other files in current files shortcode for Phile Markup.
pluginname: shortcodes.include (INCLUDE FILE)
version: 0.5
revisiondate: 23 OCT 2013
pluginauthor: jacmgr
Chapter: plugins.2
*/
## Include another page in current page
Requires the shortcodes plugin to be active.
Let's say there exists another file in your site called **testinclude.md** and it has content that looks like this:
~~~~
[include file=docs/plugins/testinclude.md raw=true]
~~~~
[[#ENDSUMMARY]]
You can include that page or any other page using the markup:
[\include file=docs/plugins/testinclude.md]
Note that this requires using the pagename `with it's extension` (this case ".md").
The result of the above markup is:
[include file=docs/plugins/testinclude.md]
Basically it merges the two pages before they are passed through the parser.
### Break a long Document to sub pages
[\include file=docs/part1.md]
[\include file=docs/part2.md]
[\include file=docs/part3.md]
## Core Changes
I added one function to the `\Phile\Model\Page` class. Needed to get the raw content without the meta for a page object. Here are the 3 methods I added, but this shortcode only uses the getContentRaw() method.
//jacmgr: set some meta
public function setMeta($key, $value) {
$this->meta->set($key, $value);
}
//jacmgr: Get the Content section of file without parsing
public function getContentRaw() {
return $this->content;
}
//jacmgr: Get the full page content
public function getRawData() {
return $this->rawData;
}
## Other formats
> WARNING: This is a dangerous shortcode. It can include any file you want into the page. You should not have it active if someone is able to modeify any of your markdown files.
### Include php snippet
If the file is not found as a phile markdown file, the shortcode will try to include the file from the php filesystem. You must provide a FULL PATH to the file. To do this I added a config variable for the folder path and allowed it to be used in the parser.
Suppose you have a folder in your content where you store snippets of php that you display in your pages as source php. In the page you can
[\include file=\%CONTENT_DIR%/codesnips/sample.01.php]
or
[\include file=\%SYSTEMFOLDER%plugins/jacshortcodes/Classes/Plugin.php]
Results in
~~~~
[include file="%CONTENT_DIR%/codesnips/sample.01.php"]
~~~~
Or include a markdown from another non-content location. AS long as it is a markdown file, we don't have to include the full path.
[\include file=../README.md]
Results in
[include file=../README.md]