CMS Development

texas-bronius
Member

Adding an editable module to a Blog template sufficient for both Blog Post form and display?

SOLVE

This is probably super straightforward, so please forgive me, but it is just an assumption on my part from reviewing docs: In order to add a text field for a content editor to fill out on a Blog Post edit form, is it sufficient to just add a "text module" to the Blog Post Template in HubL, and that's it?  Where will it fall in the order of other form fields on the Blog Post edit form?

 

Here's what I've got:

<h1>{% text "blog_post_title" label="In-Page Blog Post Title", value="{{ content.name }}", no_wrapper=True %}</h1>

My intent is that the html/browser tab <title> should be different from the <h1> page title, and that the content editor should be able to:

  • Leave the in-page title field blank (ie. on an existing blog) and still get the default content.name H1
  • Fill out the in-page title field on a blog post and see the in-page title value in the H1

I don't have sufficient access to create/edit blog posts, and I don't know of a HubSpot sandbox in this account.

 

Thanks

-Bronius

1 Accepted solution
tjoyce
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Adding an editable module to a Blog template sufficient for both Blog Post form and display?

SOLVE

@texas-bronius - A post has recently been added similar to your question. https://community.hubspot.com/t5/Content-Design-Questions/Pulling-Article-Snippets/m-p/198662#M7037

What I find easier is to use the export_to_template_context="true" attribute in the HUBL tag, that way, you can reference the text anywhere in your template by accessing the widget_data.module_name.paramater: 

https://designers.hubspot.com/docs/hubl/export-to-template-context

 


If this answer helped, please, mark as solved 😄


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

View solution in original post

0 Upvotes
2 Replies 2
tjoyce
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Adding an editable module to a Blog template sufficient for both Blog Post form and display?

SOLVE

@texas-bronius - A post has recently been added similar to your question. https://community.hubspot.com/t5/Content-Design-Questions/Pulling-Article-Snippets/m-p/198662#M7037

What I find easier is to use the export_to_template_context="true" attribute in the HUBL tag, that way, you can reference the text anywhere in your template by accessing the widget_data.module_name.paramater: 

https://designers.hubspot.com/docs/hubl/export-to-template-context

 


If this answer helped, please, mark as solved 😄


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

0 Upvotes
texas-bronius
Member

Adding an editable module to a Blog template sufficient for both Blog Post form and display?

SOLVE

Thanks a bunch @tjoyce - You nailed it.  I'll share my final solution for anyone else following these footsteps.

 

In Additional <head> Markup (on the Blog Template screen (the one where it shows all the draggable layout blocks)), I have:

{% text "page_post_title" label="In-Page Post Title", no_wrapper="true", value="", export_to_template_context="true" %}

This will provide the text field on the Blog Post Edit/Create screen (buried under the cube "modules" menu one the upper left), and its value will be available to the template as widget_data.page_post_title.value.

Then, in the Blog Post Template (the one that shows html markup for display), I replaced the existing <h1>{{ content.name }}</h1> with:

<h1>{% if widget_data.page_post_title.value %}{{ widget_data.page_post_title.value }}{% else %}{{ content.name }}{% endif %}</h1>

I put similar logic in place of the <h2>s in the Blog Listing template html.

It works!  Now, when the Content Editor enters a Blog Post Title, the value is in <head><title>..</title></head> and breadcrumb trail and H1, but when the Content Editor types a special "In-Page Post Title," that title is used in the H1 which now differs from the original Blog Post Titles on the page.

 

Cheers!

-Bronius