Display content from HTML file on a page?

I am at the stage of adding content to a site. The content, which was created in another program, consists of an HTML file and a folder of images.

Is it possible to add these as files to a page then have kirby use the content of the HTML file on the page?


Yup. I’m doing that on my site to handle legacy content.


In the meta.txt I have a ContentFile field like this:

ContentFile: index.html

Then with a meta.php template it’s trivial to show the contents of the HTML file:


if ($file = $page->contentfile()->toFile()) {
1 Like

Please note that currently Kirby does not allow uploading .html files via the Panel; you would have to add them to a folder manually.

1 Like

@fvsch How do you deal with images in that scenario?

Depends what “dealing with images” means. Just showing an image when the original HTML says <img src="something.jpg" alt="">?

In my case I have a rather specific setup where I don’t use numbered page folders, and I’m serving the content folder as my web root, so /some/page/something.jpg serves the content/some/page/something.jpg file directly. I’m “only” using Kirby to render a page if the request did not match an existing file.

In a more standard setup, you could rewrite the HTML, using a list of known files:


// Output the HTML source, replacing "image.jpg" with e.g. "/content/page/image.jpg"
if ($content = $page->contentfile()->toFile()) {
  $fileMap = [];
  foreach($page->files() as $file) {
    $fileMap[ $file->filename() ] = $file->url();
  $html = str_replace(
  echo $html;
1 Like

Is it possible to pass the content of a md file through kirbytext() so that image links work?
Something like this?

if ($file = $page->contentfile()->toFile()) {

At the moment I just get the text:


Try with the kirbtext helper (untested)

echo kirbytext($file->show());

I get the same as before unfortunately…hmmm