# Display content from HTML file on a page?

**URL:** <https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 15, 2017, 8:46am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953 "2017-03-15T08:46:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![macgyver](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@macgyver](https://forum.getkirby.com/u/macgyver)\
**Post date:** [March 15, 2017, 8:46am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/1 "2017-03-15T08:46:22Z")

</div>

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?

Thanks

---

<div class="post-metadata">

**Author:** ![fvsch](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fvsch/32/15908_2.png) [@fvsch](https://forum.getkirby.com/u/fvsch)\
**Post date:** [March 15, 2017, 9:00am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/2 "2017-03-15T09:00:00Z")

</div>

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

```auto
content/
    old-article/
        index.html
        meta.txt

```

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

```auto
----
ContentFile: index.html
----

```

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

```php
<?php

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

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 15, 2017, 9:03am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/3 "2017-03-15T09:03:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![macgyver](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@macgyver](https://forum.getkirby.com/u/macgyver)\
**Post date:** [March 15, 2017, 9:11am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/4 "2017-03-15T09:11:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fvsch](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fvsch/32/15908_2.png) [@fvsch](https://forum.getkirby.com/u/fvsch)\
**Post date:** [March 15, 2017, 10:33am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/5 "2017-03-15T10:33:44Z")

</div>

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:

```php
<?php

// 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(
    array_keys($fileMap),
    array_values($fileMap),
    $content->read()
  );
  $content->headers();
  echo $html;
}

```

---

<div class="post-metadata">

**Author:** ![macgyver](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@macgyver](https://forum.getkirby.com/u/macgyver)\
**Post date:** [March 16, 2017, 11:05am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/6 "2017-03-16T11:05:14Z")

</div>

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

```
<?php
if ($file = $page->contentfile()->toFile()) {
  $file->show()->kirbytext();
}?>

```

At the moment I just get the text:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/7/70dd135305428810acb0563b538c77e9a0ed7aa1.png)

Thanks

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 16, 2017, 11:44am UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/7 "2017-03-16T11:44:37Z")

</div>

Try with the kirbtext helper (untested)

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

```

---

<div class="post-metadata">

**Author:** ![macgyver](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@macgyver](https://forum.getkirby.com/u/macgyver)\
**Post date:** [March 16, 2017, 12:00pm UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/8 "2017-03-16T12:00:35Z")

</div>

I get the same as before unfortunately…hmmm

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:50pm UTC](https://forum.getkirby.com/t/display-content-from-html-file-on-a-page/6953/9 "2025-02-06T16:50:25Z")

</div>


