CMS Development

Paresh_Bhavsar
Member

Multiple authors for blog

SOLVE

We have a client with a requirement to be able to associate multiple authors to a single blog post. I know this is not available in Hubspot so we created a custom module to add authors to each blog and it works fine - we are 99% there. 

However, right now a user has to manuall enter name and image of every author for every blog. 

Paresh_Bhavsar_0-1664778434067.png

DESIRED 
What we want is to have the drop-down list of authors available for user to select from. All users in the list should come from here 

Paresh_Bhavsar_1-1664778536435.png


So, user enter all Authors information in deafult screen in Hubspot and we pull these values in a drop-down in a custom module to add additional authors. 

Can anyone help with what field name vaule of code we can use to fetch the drop-down? 

Thanks 
Paresh Bhavsar 
Bold Dialogue 

 

0 Upvotes
1 Accepted solution
BarryGrennan
Solution
Top Contributor

Multiple authors for blog

SOLVE

I did find my old code in the end, I wasn't far off

{# SECOND AUTHOR #}
			{% set auth_selector = [] %}
			{% set my_authors = blog_authors('default', 250) %}
			 {% for item in my_authors %}
           {% do auth_selector.append( [item, item.full_name] ) %}
              {% endfor %}
			  
			  {% choice "second_auth_selector" label="Second Author",  choices={{auth_selector}}, export_to_template_context=True %}
       {% set second = content.widgets.second_auth_selector.body.value %}
	  {% if second.name  %}
	    <div id="second_author" class="author">
		 {% if second.avatar %}
          <div class="author-image" style="background-image:url({{ second.avatar }});"></div>
	 	    {% else %}
   <div class="image-placeholder"></div>
      {% endif %}
        <div class="author-details">
	  <div class="author-name">{{ second.name }}</div>
	  <div class="author-bio">
          {% if  second.bio is containing auth_needle %}
      {{ second.bio|regex_replace("@.*$", "")|regex_replace("_", " ") }} @ {{ second.bio|regex_replace("^[^@]*@", " ")|regex_replace("_", " ") }}
      {% else %}
      {{ second.bio }}
      {% endif %}
          </div>
	  <div class="date-created">{{ content.publish_date|datetimeformat('%e %b %Y') }} </div>
		  </div>
		  </div>
		  {% endif %}

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

 

View solution in original post

5 Replies 5
BarryGrennan
Solution
Top Contributor

Multiple authors for blog

SOLVE

I did find my old code in the end, I wasn't far off

{# SECOND AUTHOR #}
			{% set auth_selector = [] %}
			{% set my_authors = blog_authors('default', 250) %}
			 {% for item in my_authors %}
           {% do auth_selector.append( [item, item.full_name] ) %}
              {% endfor %}
			  
			  {% choice "second_auth_selector" label="Second Author",  choices={{auth_selector}}, export_to_template_context=True %}
       {% set second = content.widgets.second_auth_selector.body.value %}
	  {% if second.name  %}
	    <div id="second_author" class="author">
		 {% if second.avatar %}
          <div class="author-image" style="background-image:url({{ second.avatar }});"></div>
	 	    {% else %}
   <div class="image-placeholder"></div>
      {% endif %}
        <div class="author-details">
	  <div class="author-name">{{ second.name }}</div>
	  <div class="author-bio">
          {% if  second.bio is containing auth_needle %}
      {{ second.bio|regex_replace("@.*$", "")|regex_replace("_", " ") }} @ {{ second.bio|regex_replace("^[^@]*@", " ")|regex_replace("_", " ") }}
      {% else %}
      {{ second.bio }}
      {% endif %}
          </div>
	  <div class="date-created">{{ content.publish_date|datetimeformat('%e %b %Y') }} </div>
		  </div>
		  </div>
		  {% endif %}

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

 

Paresh_Bhavsar
Member

Multiple authors for blog

SOLVE
Thank you Barry. Will try this and let you know.
0 Upvotes
BarryGrennan
Top Contributor

Multiple authors for blog

SOLVE

I did something like this for a client once. Unfortunately they're not on hubspot anmore and I don't have the code saved anywhere.

 

But for author one I'd pull it in in the standard way.

 

Then for author two, I think you can do something like use a choice tag that you fill using the recent authors tag.

You'll definitely need to fiddle around with this but it's something like 

// Empty Array
{% set authors_list = [] %}

// Get Authors
{% set my_authors = blog_authors("default", 250) %}

// Add Authors to array
{% for author in my_authors %}
{% do authors_list.append(author) %}
{% endfor %}

//Push authors into choice field
{% choice "second_author" label="Choose second author", value=authors_list %}

// Output second author
{{ second_author }}

 

Again, that's entirely off the top of my sleepless head so you'll no doubt need to fiddle with it but it's a start.
Maybe you can get {{second_author.url}} etc. from that, maybe not, maybe you need to expand what you'd adding to the array to get that.


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

0 Upvotes
LeeBartelme
HubSpot Employee
HubSpot Employee

Multiple authors for blog

SOLVE

I don't think you'll be able to do it the route you are going. If I was in your shoes, the route I would go would be to create a HubDB table with the data (name, title, image etc) about each author. Then in my module, for the field type I'd make it a HubDB row and make it use the repeater functionality.

 

When you drop that module on a post you can then select one or more authors, and use them in your module similar to how you are now.

ChehakWadhdwa
Member | Diamond Partner
Member | Diamond Partner

Multiple authors for blog

SOLVE

Hey @Paresh_Bhavsar

 

In case of Author you can retrieve only single author as author is a single selection element , multiple selection is possible only for the tags not for the author, so you can not show multiple author in dropdown as how you want.

 

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

0 Upvotes