Link to html file

Hi,

I have a blog article where i would like to link to an example html file (to explain some code visually). The html file is in the same folder as the article. How can i link to the file from the editor? It seems like uploading an html file is not allowed?

That’s right, uploading html files from the Panel is not possible. Do you want to only link to the file or embed it?

Maybe store the code in a GitHub gist instead of in an HTML file?

But I think a question like this has been asked before, let me see if I can find it :walking_woman:

Do you want to only link to the file or embed it?

Just a link to the file would be enough.

GitHub gist: looks good but i don’t think it can render HTML?

You could do it via Codepen instead, which can be embeded, and will render the html in the embedded part of the page.

Or you can read the files in a template, like the approach I describe here: Virtual pages from static HTML files (or something like that)

Or a modified concept:

content/
  html-examples/
  html-examples.txt

Then a route:

 [
      'pattern' => 'html-examples/(:any)',
      'action'  => function ($file) {
          $data = [
            'filename' => $file
          ];
          return page('html-examples')->render($data);
      }
    ],

html-examples.php controller

<?php

return function ($page, $filename) {

    return [
        'filename' => $filename
    ];
};

html-examples.php template

<?php
echo F::read($kirby->root('index'). '/'. $filename);

So when you call http://yourdomain.com/html-examples/test.html, it would read the test.html file from the root folder (or another given folder, where you store the examples).

In textfile, create link like this:

(link: html-examples/test.html)
1 Like

Solved. Thanks for the help!