CMS Development

amin9
Participant

Custom field to blog listing

I have added 2 fields, and it can display on blog single. But not in the blog listing page.

 

 

This is not working:
{{ widget_data.text_field.body.value }}

 

 

Working code on blog single page is like:

 

 

<div>Image URL: {{ widget.img4mob1.src }} </div>
<div>Text: {{ widget.text_field }} </div>

 

 

.

My main problem is:

.

On the Blog Listing page I cannot see any code is working.

Like, I have tried 1:

 

 

<div>AAA: {{ content.widgets.img4mob1.src }} </div>
<div>AAB: {{ content.widgets.text_field.body.value }} </div>

 

 

But displaying all empty on the blog listing page.

-

module:

attach1.png

0 Upvotes
3 Replies 3
Indra
Guide | Elite Partner
Guide | Elite Partner

Custom field to blog listing

@Sjardo, thanks for mentioning.

 

@amin9, to display fields onto the listing template you have to enable the parameter export_to_template_context. You can read about the option at the documentation for export_to_template_context there is a section about adding fields to the blog listing template.

 

Your field would look like this:

On a blog post template add the custom field.

{% module "custom_blog_link" path="@hubspot/text", label="Link to external press item", export_to_template_context=True %}

 

On the listing template you can do this:

{% for content in contents %}
<a href="{{ content.widgets.custom_blog_link.body.value }}">
    Click here to see this press feature!
</a>
{% endfor %}

 

Bonus tip: For each field that you add, it depends how to display the custom module. To see the dict of your custom fields you can do something like this:

{{ content.widgets|tojson }}

This will display all custom fields you have added. 


Vet Digital - The Growth Agency | HubSpot Solutions Partner Agency

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
Sjardo
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Custom field to blog listing

@Indra I'm sure you got a snippet or answer laying around!

0 Upvotes
MiaSrebrnjak
Community Manager
Community Manager

Custom field to blog listing

Hi @amin9,

 

Thank you for reaching out to the Community! 

 

I wanted to tag in a couple of subject matter experts to see if they have any advice: 

hi @Sjardo@Gonzalo@mangelet, do you any tips for @amin9? Thanks! 

 

Cheers
Mia, Community Team   


Wusstest du, dass es auch eine DACH-Community gibt?
Nimm an regionalen Unterhaltungen teil, indem du deine Spracheinstellungen änderst


Did you know that the Community is available in other languages?
Join regional conversations by
changing your language settings

0 Upvotes