Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Content & Markdown

Is there a way to render a remote/external markdown file?

Started by Trevor Ackerman 8 years ago · 1 replies · 2198 views
8 years ago

I'm interested to understand if there's a way to reference markdown content located via an URL (e.g. https://github.com/username/myrepo/README.md) and have that rendered inline with a page in Grav?

I have a wide smattering of github repos with markdown that I don't want to change.
I'd like to be able to aggregate that content within a site powered by Grav and allow creating new content that has nothing to do with any of the aforementioned github repos.

I'm open to various solutions such as plugins, Twig, etc.

Any suggestions?

Cheers,
Trevor Ackerman

8 years ago

It's possible, but not out-of-the-box.

1) Create a custom twig function to pull a remote URL into a string, then use the |markdown filter on that string. The problem here is that there's no caching, and every page requests has to request this file and parse it.

2) Create a custom plugin that retrieves the file, markdown-parses it and stores it as a variable. Potentially, you could add caching to this call so it's not run every time.

3) Create a cron job or something that simply pulls the remote file and stores it in the Grav user/pages/ structure, so Grav treats it like a regular markdown page that you can access and display with page->find('/username/myrepo/README.md')->content()

There are other ways, but that's just 3 off the top of my head.

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 99 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 186 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 148 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 62 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 257 1 year ago