CMS Development

Demetri
Mitglied | Partner
Mitglied | Partner

Add custom fields to blog posts

lösung

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 Akzeptierte Lösung
Anton
Lösung
Trendsetter/-in

Add custom fields to blog posts

lösung

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

Lösung in ursprünglichem Beitrag anzeigen

5 Antworten
rupaknepali
Mitglied

Add custom fields to blog posts

lösung
0 Upvotes
Demetri
Mitglied | Partner
Mitglied | Partner

Add custom fields to blog posts

lösung

The people creating the blog post.

0 Upvotes
Anton
Lösung
Trendsetter/-in

Add custom fields to blog posts

lösung

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
Teilnehmer/-in | Partner
Teilnehmer/-in | Partner

Add custom fields to blog posts

lösung

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

0 Upvotes
Anton
Trendsetter/-in

Add custom fields to blog posts

lösung
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