Check if post is scheduled in post.hbs

In my post.hbs I need to be able to check if the current page has a publish date in the future i.e. the post has been scheduled.

Today I have:

{{#if published_at }}
<section class="post-full-comments">
	<div id='discourse-comments'></div>
	<script type="text/javascript">
	...
	</script>
</section>
{{/if}}

But when you schedule a post it seems to get a published_at that is in the future.

In psudeo code I would like to do something like

{{#if published_at > Date.now() }}
  ...
{{/if}}

Ghost version: 2.38.3

Thanks in advance if you would take some time and help a noob like me.

@Olle_Jacobsen scheduled posts aren’t published (public) yet so they are not available in the front-end or via the Content API.

What’s the use-case you are trying to solve by checking the scheduled status?

Thanks for you answer Kevin.

So my use-case is the following.

I’m using Discourse to handle my comments on posts and pages. When a page/post is loaded (via regular page view or a preview) Discourse will create a new topic with a link to the source (the blog post/page link). So when I work with a new post and click preview the following block will make sure Discourse isn’t notice the the unpublished post.

{{#if published_at }}
<section class="post-full-comments">
	<div id='discourse-comments'></div>
	<script type="text/javascript">
	...
	</script>
</section>
{{/if}}

But if I schedule the post the {{#if published_at }} is “trutly” and will create a new topic in Discourse when I click preview on my scheduled post. Due making part of the post visible for the Discourse members and with a link to the post on the blog before it is published.

So in this case I’m basically looking for a {{#if published }} but that doesn’t seems to exist. So I was looking for a way to “extend” the usage of {{#if published_at }} in a way so I can check in the hbs if the post/page really is published and available for the public.

OK, published_at is not the right thing to use here, as you’ve found it can be set at any point before publishing by setting a past or future (scheduled) published_at date.

Instead, you should be able to use the {{is}} helper to check the context, eg:

{{^is "preview"}}
<section class="post-full-comments">
	<div id='discourse-comments'></div>
	<script type="text/javascript">
	...
	</script>
</section>
{{/is}}
2 Likes