PageFactory (Kirby Plugin)

Import()

Loads content from a file.

import()

Loads content from a file.

Arguments

file
[filename] Loads given file and injects its content into the page. If "file" contains glob-style wildcards, then all matching files will be loaded. If file-extension is ".md", loaded content will be markdown-compiled automatically. (default: false)
literal
If true, file content will be rendered as is - i.e. in <pre> tags. (default: false)
highlight
(true|list-of-markers) If true, patters `, `` and “```` are used. These patterns will be detected and wrapped in "<span class='hl{n}'> elements". (default: false)
mdCompile
If true, file content will be markdown-compiled before rendering. (default: false)
wrapperTag
If defined, output will be wrapped in given tag. (default: false)
wrapperClass
If defined, given class will be applied to the wrapper tag. (default: )

Examples

Note: Normally, all .md files in a page folder are loaded and rendered automatically.
To exclude an md-file, prepend - to its filename, e.g. -import.md.

Import Markdown Source File

Before
{{ import(-import.md) }}
After

Rendered Output:

Before

This text stems from file "-import.md".

After

Import HTML Source File

Before
{{ import(-import.html) }}
After

Rendered Output:

Before

This text was imported from "-import.html"

After

Literal Output

{{ import(-import.html, literal:true) }}

Rendered Output:

<div class='box'>
    <p>This text was imported from "<em>-import.html</em>"</p>
</div>

Literal Output with Highlighting

Experimental:

Currently supported patterns:

  • `XY`
  • ``XY``
  • ```XY```
 
{{ import(sample.php, literal:true, highlight: true) }}

Rendered Output:

<!DOCTYPE html>
<html lang="en</span>">
<head>
  <meta charset="utf-8" />
  <title>{{ title }}</span></title>
</head>
<body>
  <?= $page->pageContent() ?></span>
</body>
</html>

Import with Specific Wrapper

{{ import(-import.txt, wrapperTag:p, wrapperClass:box) }}

Rendered HTML:

<p class='pfy-imported pfy-imported-5 box'>
    "Lorem ipsum"  imported from '-imported.txt'.
</p>

Rendered Output:

"Lorem ipsum" imported from '-imported.txt'.