Add custom fields to blog posts

SOLVE
Demetri
Member | Partner

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

Accepted Solutions
Anton
Solution
Key Advisor | Diamond Partner

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




check
Did my post help answer your query? Help the Community by marking it as a solution



View solution in original post

3 Replies 3
Anton
Key Advisor | Diamond Partner
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



check
Did my post help answer your query? Help the Community by marking it as a solution



Demetri
Member | Partner

The people creating the blog post.

0 Upvotes
Anton
Solution
Key Advisor | Diamond Partner

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




check
Did my post help answer your query? Help the Community by marking it as a solution



View solution in original post