CMS Development

giozua
投稿者 | Platinum Partner
投稿者 | Platinum Partner

custom module - choose the blog

解決

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 いいね!
1件の承認済みベストアンサー
dpeters
解決策
HubSpot Employee
HubSpot Employee

custom module - choose the blog

解決

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

元の投稿で解決策を見る

7件の返信
Jsum
キーアドバイザー

custom module - choose the blog

解決

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 いいね!
giozua
投稿者 | Platinum Partner
投稿者 | Platinum Partner

custom module - choose the blog

解決

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

0 いいね!
Jsum
キーアドバイザー

custom module - choose the blog

解決
Will you paste your code here so i can take a look?
0 いいね!
giozua
投稿者 | Platinum Partner
投稿者 | Platinum Partner

custom module - choose the blog

解決

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 いいね!
dpeters
解決策
HubSpot Employee
HubSpot Employee

custom module - choose the blog

解決

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
投稿者 | Platinum Partner
投稿者 | Platinum Partner

custom module - choose the blog

解決

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 いいね!
Jsum
キーアドバイザー

custom module - choose the blog

解決
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 いいね!