CMS Development

Demetri
Member | Partner
Member | Partner

Add custom fields to blog posts

SOLVE

I would like to add custom fields to a blog post, for example a checkbox called "Featured Post". Then i would like to have access to this data within hubl code, so i can apply logic in the template 

0 Upvotes
1 Accepted solution
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Add custom fields to blog posts

SOLVE

Hi @Demetri

okay - that's much easier to do 😉

 

You have multiple options:

  1. create an if-loop inside the blog-post template and wrap it around the featured post code. By doing so the author will get an option("module") when creating a new post.
  2. create a new module with an if-loop and the featured post code. Personally I go almost always this way because it gives you much more flexibility(you could even show a featured post from another blog if you have mutliple ones). After creating this module you place the module where you want to show the optional featured post. 

 

Here some code examples for both solutions

 

if-loop directly in template

{% boolean "show_featured_post" label='Show Featured post', value=True, export_to_template_context=True %}
...
{% if widget_data.show_featured_post %}
   place your featured post code here
{% endif %}

place this code inside your blog-post(not listing) template. The if-loop should be in the place you would like to show the featured post.  

 

 

if-loop in module and template

 

module

{% if module.show_featured_post %}
place your code here
{% endif %}

 

template

...
{% module 'Featured Post' src="PATH-TO-MODULE", no_wrapper=True %}
...

 for the "easiest" use I would recommend to right-click the module in the left sidebar of the design-manager and select "Copy snippet". Place it in the template where you'd like to display the module. Also I recommend to add the no_wrapper=True option at the end of the module. This will minimize the sourcecode slightly by not using unneeded wrapping divs

 

 

best, 

Anton

Anton Bujanowski Signature

View solution in original post

5 Replies 5
rupaknepali
Member

Add custom fields to blog posts

SOLVE
0 Upvotes
Demetri
Member | Partner
Member | Partner

Add custom fields to blog posts

SOLVE

The people creating the blog post.

0 Upvotes
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Add custom fields to blog posts

SOLVE

Hi @Demetri

okay - that's much easier to do 😉

 

You have multiple options:

  1. create an if-loop inside the blog-post template and wrap it around the featured post code. By doing so the author will get an option("module") when creating a new post.
  2. create a new module with an if-loop and the featured post code. Personally I go almost always this way because it gives you much more flexibility(you could even show a featured post from another blog if you have mutliple ones). After creating this module you place the module where you want to show the optional featured post. 

 

Here some code examples for both solutions

 

if-loop directly in template

{% boolean "show_featured_post" label='Show Featured post', value=True, export_to_template_context=True %}
...
{% if widget_data.show_featured_post %}
   place your featured post code here
{% endif %}

place this code inside your blog-post(not listing) template. The if-loop should be in the place you would like to show the featured post.  

 

 

if-loop in module and template

 

module

{% if module.show_featured_post %}
place your code here
{% endif %}

 

template

...
{% module 'Featured Post' src="PATH-TO-MODULE", no_wrapper=True %}
...

 for the "easiest" use I would recommend to right-click the module in the left sidebar of the design-manager and select "Copy snippet". Place it in the template where you'd like to display the module. Also I recommend to add the no_wrapper=True option at the end of the module. This will minimize the sourcecode slightly by not using unneeded wrapping divs

 

 

best, 

Anton

Anton Bujanowski Signature
adriancblack
Participant | Partner
Participant | Partner

Add custom fields to blog posts

SOLVE

How do you bring the custom fields to the listing view? It used to work but it no longer does.

0 Upvotes
Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Add custom fields to blog posts

SOLVE
Hi @Demetri,
Do you mean a checkbox for your team/customer who is creating the blog post per the visitors of the blog post who don't have access to hubspot?

Best,
Anton
Anton Bujanowski Signature