How to Create a Custom Post Template With "Snippets" Embedded Within {{content}}

Hi there,

I’ve been looking everywhere on Google and on Ghost forum but did not manage to find a solution, so I am writing a new topic to see if someone might have some idea on how to implement a “Custom Post Template with Embedded Snippets”, which sounds like a totally impossible task at the moment.

I understand that {{content}} is where all author-created-input will be injected into a post on pageload.

While the current Ghost Post Template, seems to allow for any “html code changes” to the headers or footer pre-loads prior to a post’s pageload.

My question would be will it be possible to have a “Template structure” that will have multiple, standardised “subheader html segments” (Snippets in the current Ghost system), pre-loaded in a Ghost Post Template, when I pull out a Custom-Post-Template within a new Post creation.


Current Ghost Post Template System (My understanding)

...
<customheader />
{{content}}
<customfooter />
...

My Preferred version of Ghost Post Template System

...
<customheader />

>>---START Within {{content}}

<subheader1 />
<opencontentareafornewwriting1 />
<subheader2 />
<opencontentareafornewwriting2 />

>>---END Within {{content}}

<customfooter />
...

I’m not sure if someone can generally understand what I am getting at. Do let me know if I need to add more info to provide a better picture. As I am hoping to load a Custom Post Template that will have either a few preset snippets loaded together that are spaced apart by user-writeable space, or just have this whole set preloaded when a selected Custom Post Template is called.

Hope someone can assist on this! Much appreciate! Thanks!

That’s not possible with templates. Sounds like you’d be better off creating the “template” as a snippet as that’s what they are intended for.

Hi @Kevin ,

I was thinking about that. But, I had wanted just “snippets blocks” included, where standard <subheader> blocks will be pre-loaded, and there will be the normal “writeable” space for me to just freely type away when the template is preloaded.

However, the easiest method I can think of right now is to use the HTML Block snippet, but for this, I have to type everything in HTML code, which is not what I wanted, as I wanted to freely insert any other snippet blocks freely during my writeup.

Given so, is there any more “flexible” snippets blocks, which may allow me to pre-load multiple HTML <subheader> into one big snippet blocks or the only way is really to save all these <subheader> blocks into multiple snippets where I have to manually load into the page while writing?

Would there be any way around? Or would there be any potential changes in the Ghost system’s roadmap that will help on this? Just to check? Thanks!

Any selection can be a snippet, not just individual cards.

  1. Create a page with your html blocks and empty writing spaces
  2. Select all of the contents (Ctrl/Cmd+A can be easier than click+drag for long posts)
  3. Click the “Create snippet” toolbar button
  4. Use that snippet when creating a new post

8 Likes

Hey @Kevin,

Wow! I didn’t know you can do that! Yeah! Now that is something that will work for my current use-case!

Just perfect! Thank you so much! Plugs my current problem perfectly! Thank you!

@Kevin ,

do you think this feature has been documented somewhere ? i have a hard time searching for this in the official Ghost resources.

Snippets are covered in the editor help documentation Using the Editor in Ghost - FAQ

1 Like

@Kevin ,

thanks for your prompt reply.
and if i used the same snippet in more than 1 posts, then in a certain post i update that inserted snippet, will that change be reflected in all instances which exist in other published posts ?

No. Snippets are just like copy/paste but you have a stored list of things to “copy”. Once they’ve been inserted into a post they are indistinguishable from any other content in that post exactly as if you copy/pasted it from elsewhere.

@Kevin ,

Snippets are just like copy/paste but you have a stored list of things to “copy”

got it.

so if i have a particular custom feature to be added in some of my posts, with future updates expected, what do you recommend as the best approach, so that for all future updates, a single modification can have all instances updated as well ( i.e. without having to adjust each posts manually ) ?

See this thread, to the end.

1 Like

@Kevin - thanks for helping out so far. Question: I have seen the video created by you and of course we can create dyanmic HTML snippet right inside the editor and re-use them.

But I want to version them in the code. So I want to create my custom template, render the snippet code inside my .hbs file and as soon as I attach the template inside the ghost CMS editor, I want to immediately load the HTML snippets. Then of course I can edit them and add text etc and publish the page.

Do you think its possible? If you can show a way to do that.

Hi @Kevin,
Sorry for digging an old subject but I just tried your method to create a multiple node snippet and when I select all the content using CTRL+A, either I am on a text node and it triggers the blockquote feature or I am on a HTML node and it does nothing…
I also tried to select all content manually with the mouse but cannot select both text & html node.

I succeded in a previous version of Ghost but now it does not work anymore

Ghost version : 5.59.2 with Beta Editor (tried without, not working neither)

Hey there!

I was trying to duplicate the bug you were having but I couldn’t.

Here’s a video of what it looks like for me:

Can you share more about what’s happening for you?

Hi @RyanF
Thanks for your quick answer!

While doing the screencast I might have igured out a workaround but it is still not working as expected.
It is strange: the toggle blockquote key shortcut CTRL+Q is only working with CTRL+A on my computers (tested on 2, both using AZERTY as keyboard layout).

That’s why I cannot use CTRL+A to select everything on my page while being on a text node.

However, when I am on a HTML node, doing CTRL+A toggles all text blocks to blockquote BUT also select everything and allow to create a snippet.

Here is the video below
https://imgur.com/a/5y4qc35

Thanks for following up. Is this on Windows?

I tried both on Windows and Ubuntu.

Both using last version of Firefox

Do you have a Chromium browser that you can test?

I just tried with Chromium and it is not working :/

However the behavor is different: when I hit CTRL+A, it selects everything (at least I think, the HTML nodes are not in a “selected” style = highlited border) even if I am in a text node (it does not trigger blockquote).

But in all cases, usnig CTRL+1 or drag to select, the toolbar does not appear…

Do you need another screencast?

A recording would be great :pray:
I’m going to take a look on Windows to see if I can replicate it because I haven’t been able to on MacOS.

I just saw a commit potentially related to this issue: 🐛 Fixed code/html/markdown cards being removed when cutting content i… · TryGhost/Koenig@c84218e · GitHub