CMS Development

andreasmb
Contributor

Passing a variable into blog_post_by_id ?

SOLVE

Hi there,

 

I'm trying create a page where my marketing colleagues can insert a specific post from any of our blogs. A great to way to achieve this seems to be to use "blog_post_by_id", like this :

 

 

{% text "post_id" label="Post's - ID number", export_to_template_context=True %}

{% set post = blog_post_by_id( {{ post_id }} ) %}

 

 

Sadly, this doesn't seem to work, and Hubspot's documentation indicates that the function only accepts a numeric ID. Seems like an odd limitation.

Does anybody know a workaround? Or perhaps I've misunderstood what the blog_post_by_id function does, and there's actually a way to do this.

I know I could use a for loop and iterate through a bunch of posts until I find the one with the ID I'm looking for, but that seems very tedious, especially given that I'm fetching posts from multiple different blogs. 

 

0 Upvotes
1 Accepted solution
andreasmb
Solution
Contributor

Passing a variable into blog_post_by_id ?

SOLVE

Ah, it looks like I got my syntax wrong – here is how it should be formatted:

 

{% text "post_id" label="Post's - ID number", export_to_template_context=True %}

{% set post = blog_post_by_id(post_id.value) %}

View solution in original post

1 Reply 1
andreasmb
Solution
Contributor

Passing a variable into blog_post_by_id ?

SOLVE

Ah, it looks like I got my syntax wrong – here is how it should be formatted:

 

{% text "post_id" label="Post's - ID number", export_to_template_context=True %}

{% set post = blog_post_by_id(post_id.value) %}