CMS Development

giozua
Mitwirkender/Mitwirkende | Platinum Partner
Mitwirkender/Mitwirkende | Platinum Partner

custom module - choose the blog

lösung

Hi, I'm creating a custom module to have a slider post.
I need to choose the blog from a list and have the number of posts to display. The syntax to set the blog is this: {% set posts = blog_recent_posts('default', 5) %} but how do I make dynamic the field "default" = blog name or its id, and the field "5" = number of posts to be displayed?

I've tried with this sintax

{% set posts = blog_recent_posts('{{widget.blog_name}}', '{{widget.n_posts}}') %}

but do not work

Can anyone help me?

Many thanks

 

Giovanni

0 Upvotes
1 Akzeptierte Lösung
dpeters
Lösung
HubSpot Employee
HubSpot Employee

custom module - choose the blog

lösung

Hi Gio,

 

When you are within a HubL statement, it is not necessary to wrap HubL tokens in expression delimiters

 

{{ }}

 

 Making these slight changes to your code should get this working

 

{% text "blog_id" label="Blog ID", value="4495212459", export_to_template_context=True %}
{% set post_num = [1, 2, 3, 4, 5, 6] %}
{% choice "blog_limit" label="Number of Posts", value="5", choices="post_num", export_to_template_context=True %}
{% set posts = blog_recent_posts(widget_data.blog_id.value, widget_data.blog_limit.value) %}

 

Best,

Danielle

Lösung in ursprünglichem Beitrag anzeigen

7 Antworten
Jsum
Autorität

custom module - choose the blog

lösung

How are you wanting to edit this? from the page editor?

 

You could create editable fields: 

 

 

{% text "blog_id" label="Blog ID", value="12345678", export_to_template_context=True %}

{% set post_num = [1, 2, 3, 4, 5, 6] %}
{% choice "blog_limit" label="Number of Posts", value="5", choices="{{ post_num }}", export_to_template_context=True %}

 

Then assign the values to the blog search funtion:

 

 

{% set posts = blog_recent_posts('{{ widget_data.blog_id.value }}', '{{ widget_data.blog_limit.value }}') %}

 

this would create editable fields on the editing page. You would put the blog ide in the text field, and use the choice dropdown to choose the blog limit. 

 

Let me know if this is what you need and if it works.

 

0 Upvotes
giozua
Mitwirkender/Mitwirkende | Platinum Partner
Mitwirkender/Mitwirkende | Platinum Partner

custom module - choose the blog

lösung

yes this is exactly what I need, but unfortunately does not work and I do not understand why

0 Upvotes
Jsum
Autorität

custom module - choose the blog

lösung
Will you paste your code here so i can take a look?
0 Upvotes
giozua
Mitwirkender/Mitwirkende | Platinum Partner
Mitwirkender/Mitwirkende | Platinum Partner

custom module - choose the blog

lösung

Thanks for help me

---------

{% text "blog_id" label="Blog ID", value="4495212459", export_to_template_context=True %}
{% set post_num = [1, 2, 3, 4, 5, 6] %}
{% choice "blog_limit" label="Number of Posts", value="5", choices="{{ post_num }}", export_to_template_context=True %}

{% set posts = blog_recent_posts('{{ widget_data.blog_id.value }}', '{{ widget_data.blog_limit.value }}') %}

<p>{{ widget_data.blog_id.value }}</p>

----------

the last row is for test

 

Gio(vanni)

 

0 Upvotes
dpeters
Lösung
HubSpot Employee
HubSpot Employee

custom module - choose the blog

lösung

Hi Gio,

 

When you are within a HubL statement, it is not necessary to wrap HubL tokens in expression delimiters

 

{{ }}

 

 Making these slight changes to your code should get this working

 

{% text "blog_id" label="Blog ID", value="4495212459", export_to_template_context=True %}
{% set post_num = [1, 2, 3, 4, 5, 6] %}
{% choice "blog_limit" label="Number of Posts", value="5", choices="post_num", export_to_template_context=True %}
{% set posts = blog_recent_posts(widget_data.blog_id.value, widget_data.blog_limit.value) %}

 

Best,

Danielle

giozua
Mitwirkender/Mitwirkende | Platinum Partner
Mitwirkender/Mitwirkende | Platinum Partner

custom module - choose the blog

lösung

Ok this is very strange, because inside a custom modul the script don't work instead directly inside hubl module this work fine!!! Yeah

Thanks a lot 

 

Gio(vanni)

0 Upvotes
Jsum
Autorität

custom module - choose the blog

lösung
Your creating a array. To get the data from it you have to loop through it with a for loop. {% for post in posts %}{% endfor %}

Then you access the data by targeting post. {{ post.name }} post being the single item name in the for loop.
0 Upvotes