CMS Development

jedthehumanoid
Member

List automatically using page titles as links

I'm creating a module with a list of pages. I can easily do this, but for each item I have two fields - Text  (for the editor to add the page name in) and Page (for the editor to select the page)

 

is there a way for it to automatically display the page name when I select the Page?

 

Hope that makes sense. Thanks in advance!

0 Upvotes
4 Replies 4
dennisedson
HubSpot Product Team
HubSpot Product Team

List automatically using page titles as links

@jedthehumanoid --

is this what you need?

{{ page_by_id(module.page_field).name }}

i often find it useful to add the pretty print filter to the end so i can see all of the available info like this:

{{ page_by_id(module.page_field)|pprint }}
jedthehumanoid
Member

List automatically using page titles as links

Hi Dennis. Thanks for the info. I'm new to hubspot as you may have guessed. I've manaed to get this working using the following code:

 

<div class="custom-module" id="{{ name }}">
  	<div class="cell-wrapper">
      	<div class="text">
          	<h2 class="header" style="text-align:left">{{ module.text.header }}</h2>
      	</div>
      	<div class="">
          	{% for item in module.items %}
						{% set my_page = page_by_id(item.url) %}
          	<div class="related-item-list">
              <ul>
                <li><a href="{{ my_page.absolute_url }}">{{ my_page.title }}</a></li>
              </ul>
              
          	</div>
          	{% endfor %}
  			</div>
  	</div>
</div>

Is there a better way I should be doing this? Here's how it displays in the editor:

 

Capture.JPG

 

(I have no idea where 'Job title' is coming from)

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

List automatically using page titles as links

change:

{% set my_page = page_by_id(item.url) %}

to:

{% set my_page = page_by_id(item.url).name %}

and this:

 <li><a href="{{ my_page.absolute_url }}">{{ my_page.title }}</a></li>

 to:

 <li><a href="{{page_by_id(item.url).absoluteUrl }}">{{ my_page }}</a></li>

 

 

jedthehumanoid
Member

List automatically using page titles as links

Thanks Dennis, that works brilliantly. Are you able to explain what your changes have done? Or poitn me in the direction of somewhere where I can learn?

 

Thanks again

0 Upvotes