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

6 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