Howdy, I am doing a bit of a training exercise and was hoping to get some confirmation on one aspect of the blog feature, thanks for looking…
It seems that `
blog_post`
instances, “blog posts”, are architected by HubSpot to start as a very simple RTE/body area with very few additional built-in author fields: title, featured image, meta description, author field, tagging and so on. I assume it’s intended as a clean and simple way authors can focus on writing, which makes sense to me for sure. Yes DnD is an optional addition, but ideally they’re not doing crazy amounts of building in a blog post, but anyway…
Given a requirement for, say, even just one additional blog post field at a “page level” for a simple blog post, so far I have identified you can either:
- Use a custom module, with even just a simple single primitive-ish field if you want, like text.
-
The custom module can be then be embedded within the
`blog_post`
template, thereby categorizing it as a “static module” when looking at the Content pane. In addition to the Content pane, the author can actually also see it within the body content and click it in the page which opens the Content pane for them. This is quite nice.
-
The custom module could be drag-and-drop by the author. But given the requirement in my example is to have this field by default in the `
blog_post`
workflow, we can ignore this option for now.
-
- Alternatively, it appears you can also use the module HubL tag syntax within the `
blog_post`
template with `
export_to_template_context
` set to true.
- This puts the module instance in the Content pane inside a section called “Hidden Modules,” (really not my favourite name, but I get the reference to Visibility.) This time the author can only see the value if they physically click on the Content pane to edit it, there would not be anything for them to see and click on in-page. (Read: they have to know via training to set it, which I like less.)
Firstly, I would just like to confirm are these the two standard methods for adding a new/custom field to a blog_post template?
Now more importantly, working with “the loop”… so rendering the content in the `
blog_post
` template in those cases above is straight forward. However, rendering the content within a loop of items from, say, `
blog_recent_tag_posts
` inside a `
blog_listing
` might force our hand here…
From what I have tested thus far, [again, new and training so please correct me if..] the only method I’ve found to be able to access the content from the custom field methods above within the loop is via the `
export_to_template_context
` syntax option (2) above.
I’d like to pause here and ask, is this also correct, has anyone seen another method?
Finally, the documentation on this feature says:
export_to_template_context=True is not supported in custom modules, as it serves no real purpose for them. You do not need to use export_to_template_context to get the value of a module within a template, you can already access it.
While it’s true you can access content “on page” with any method, it does seem odd to me that I can’t access a custom modules’ instance values while running through the loop unless I use a specific method. Now, perhaps I’ve missed it in the docs, but I was hoping you could confirm this, or show an alternative if it’s possible. At then end of the day I like how the custom module is visible/click-able in the post [if you want it to be], but am not able to find information on how to access that method in a loop.
Thanks very much!
Allan