You are here

Displaying a List of Content From Another Page

Submitted by Meredith on January 31, 2012 - 12:00am

Updated 1/31/12

Have you ever wanted to have content from one of your webpages show on another page on your site? For example, perhaps you’d like to pull some of your blog headlines onto your homepage? Well, there is an easy way to print content from one page onto another on your NationBuilder website. In this post, we’ll walk you how to create this effect.

Throughout this task, there are 3 places you'll need to edit or refer to in NationBuilder:

  1. a new custom template, which will display the data the way you'd like it to transfer from one page to the other
  2. the page you want to pull content from
  3. the page you want to display the content on

Start by making your new custom template file. To do this, go to Pages> Theme > Custom Theme > New File. Name your template something like "_Blog_exerpts.html" - note the leading underscore and .html at the end. Then save the template.

Now put your code in the new template. This code pulls information from the page you’d like to print, and displays it in the way you’d like it displayed. Following the example of printing your blog headlines on another page, you’d put the following code in your custom template and save.

  1. {% for post in page.blog.most_recent_blog_posts %}
  2. <div style="margin:0 0 0 5px; line-height:1.2em;" class="page_excerpt padbottom" id="blog_post_page_{{ post.id }}">
  3.   <a href="{{ post.url }}">{{ post.headline }}</a>
  4. </div>
  5. {% endfor %}

If at anytime you’d like to edit your code, you can come back to edit this html file here: Pages> Theme > Custom Theme > Files.

Next, create the liquid markup tag for this action. The final product will follow this convention:

  1. {% subpage "page_slug" with "template_example" %}

To create your tag:

Put the slug for the original page you’re drawing content from inside the liquid tag, where it says "page_slug".

Then put your custom template file name in the place where it says "template_example" - without the leading underscore, and without the .html at the end.

So, following the blog headlines on homepage example, our final tag would be

  1. {% subpage “blog” with “Blog_exerpts” %}

Place this code in the template of the page on which you’d like your content to print. Save, and style accordingly!

More of a visual learner? Watch our screencast:

Finally, Nationbuilder also provides support on this topic as well. Below is a screenshot of the official NationBuilder documentation (as of Aug 21). You can find this in their theme documentation here.