Serving XML rendered outside of handlebars

I’m looking for a way to serve XML through Ghost that’s been created elsewhere - i.e. isn’t rendered by Handlebars as in the documentation.

Aside - this is part of a workaround for the lack of necessary attributes in Ghost to properly manage a podcast feed (like epsode number, the explicit flag, etc…). If those existed, I wouldn’t need to get XML working this way. But they don’t, so I do.

What I’d like to do is get Ghost to render a page in a similar way to that in the docs above, but with completely arbritrary text content that I can set through the API.

The approaches I’ve explored so far are:

  • Create a placeholder Handlebars template which simply renders the XML information stored elsewhere - This is my preferred approach, but it fails because there isn’t a way to render plain-text page content. The excerpt attributes, whilst plaintext, aren’t large enough to store the contents of the file.
  • Uploading a file to Ghost - The only file uploads I can find in the API documentation are for images. This means that the object will have the wrong MIME type, plus the URL that files get uploaded to can’t be made consistent, it changes with the date.

Limitations for this use-case:

  • Because this is XML there’s no client-side rendering options. All has to be done server-side.
  • HTTP redirects can’t be used.
  • The path needs to stay the same when the data is changed, so it can be referenced elsewhere.
  • I’m using Ghost Pro, so I can’t modify Ghost’s own code.
  • The contents change relatively regularly, so this isn’t a set-and-forget kind of thing.

At the moment, my least-bad option is going to be to upload the file to internet-facing storage elsewhere. Which isn’t ideal when my goal has been to move everything over to Ghost!

Not sure I’m fully following what you are trying to do but could you follow a similar approach to the custom RSS feed docs but in your “XML” posts create a HTML card and put your XML contents in the card? If you do that the post’s html field will only contain XML so you can include it in a template as you see fit.

Thank you - The core of what I’m trying to do is store some XML somewhere in Ghost and get it rendered also as XML readable from the internet.

I think I follow what you’re suggesting. If I have, I’m afraid it doesn’t work.

What I did:

  • Created a template with
    {{#post}} {{content}} {{/post}} in it
  • Associated it with a test page rendered as XML in routes.yaml
  • Added the XML I want to see to a raw HTML card on that test page

Doing this results in an empty XML document, whether the contents of the card contain XML or not. This is always true for anything that’s XML content, it doesn’t get rendered. Perhaps it’s sanitised somewhere?

I think the problem here is that the approach in the docs doesn’t actually store any XML in Ghost, it’s all HTML and plaintext content. All of the XML is in the handlebars template. Which doesn’t fit my needs, unfortunately.