Hide part of the template with something in the post content

Using Ghost 2.21

Right now I have a comments portion in my template file for posts, what I’m wondering is there any way to put something in my post while writing, that could hide that portion of the code.

I know I can make a separate template to simply not include comments, but I’m hoping I can figure out a solution where I could put something in my template around my comment section such as {{#if comments}}, with comments set to true by default, and then in my post when I want to disable comments I could just add something like {{#set comments false}} at the bottom or something like that.

I also have a second question(New to ghost here, searching through docs but not finding exactly what I’m looking for), is it possible to create a “snippet” of code, that is reusable in posts? So I could have some code that preferably takes a parameter and in my post just do something like {{include template-name}}?
I managed to find partials on this page https://docs.ghost.org/tutorials/related-posts-block/, and some google searchfu taught me you can pass parameters(although I haven’t tested it yet)

Again sorry if these have been answered too many times but I’m not having luck finding what I’m hoping for.

Hey @bittiez :wave:

I wanted to clarify something first - handlebars in your post is never interpreted by the Ghost Theme Engine. The entire post is provided as a chunk of sanitized data that handlebars uses.

Ghost doesn’t have support for something like what you’re asking about right now; the best route for this is custom templates :slight_smile: You might find the Custom Fields idea interesting:

With custom templates, you can use partials to limit the amount of code repetition if that’s an issue.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.