Introduction to NationBuilder theming

Theming in NationBuilder is fully featured and easy to learn. You can customize any element of the user facing website and have access to all the objects and variables that make NationBuilder so powerful. NationBuilder extends HTML with the Liquid template language, and extends CSS with SASS. All that means is you can use regular HTML and CSS, but you also get some cool plugins, variables, and logic in both. Have you noticed how easy it is to change the color scheme of the Revolution theme? That all happens with SASS and a couple of color variables.


Official themes
From the start, your new nation will automatically be using one of our beautiful official themes. You can instantly switch between themes by clicking Pages, Theme and then clicking on one of the thumbnails. Each theme also has a set of styles to choose from.

Using one of our official themes is the quickest way to get your nation online and looking great.


Create your own custom theme

To create your own custom theme, sign in to your control panel and click Pages > Theme > New custom theme.

The Template page displays all the theme level page and autoresponse templates you can edit. If you have modified a template, it will say "Yes" under the custom column. To upload images, SCSS, javascript or other files click on Files and then Upload. Reference these files in your HTML and SCSS without any path and use the filename theme.scss for your SCSS file, like so:

Learn more about the appropriate way to reference images and other files in NationBuilder.

Your new theme won't be published to your website until you're ready. As you build your theme, you can view all the changes you make within the theme editor by clicking Save as draft, then clicking on the Preview button. Use the drop downs at the top of the preview pane to choose which theme and page you want to view.

Clicking Publish Theme won't actually publish changes to your website until you select your theme. You select your theme from the Pages, Theme page. You shouldn't select your theme until it's finished and ready to go live.

To create a thumbnail for your theme, take a screenshot and resize it to 222x139. Name it theme.png and upload it to the Files page.

Learn the important distinction between theme and page level editing.


How to reference images and files

Upload images and files to Pages > Theme > Files if you are going to reference them in a theme level template (meaning all templates listed under Pages > Theme). Upload images and files to the Files page of a particular page if you are going to reference them on a page level template or the wysiwyg editor within the Content area of a page.

You should only ever reference images, stylesheets, and javascript files using just the file name, not the full URL.

This applies everywhere:

  • Images in SCSS or CSS files
  • Images in img tags:
  • Images in CSS tags:
  • Images in inline CSS attributes:
  • SCSS or CSS files linked in the header:
  • Javascript files linked in the header:

Never link to an absolute URL (ie. http://d3n8a8pro7vhmx.cloudfront.net/.../myimage.jpg) , as they are likely to stop working eventually.

The only exception is if you are referencing an image or file within a <script> tag. In that case, upload the file to Pages > Theme > Files and use the following code:


Liquid template language basics

NationBuilder uses the open source liquid template language to access objects and variables. There are two basic types of markup in liquid:

Output is surrounded by
{{ two curly brackets }}

Tags are surrounded by
{% a curly bracket and a percent %}

Output blocks are replaced with the data they reference, such as printing the name of a supporter:

{{ signup.published_name }}

Tags drive the logic of templates. They are responsible for loops and branching logic such as If / Else.

Example of output blocks and tags in use:


SASS
SASS is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance and more.

We use the SCSS syntax of SASS, which is almost identical to CSS. Here's an example of some of the benefits:

Variables:

Mixins:

Mixins are one of the most powerful Sass features. They allow re-use of styles – properties or even selectors – without having to copy and paste them or move them into a non-semantic class.

For example, let's say you want rounder corners on a background element. Instead of typing out the border-radius property for all the different browsers, you can just use the border-radius mixin like so:

Of course there's much more SASS can do, so view more SASS tutorials or check out the reference docs before getting started.
Stylesheet

The main stylesheet for each theme is a SCSS file called theme.scss. When you create a new custom theme, you will start with the theme.scss from the official Basic theme. To make it a bit easier to structure your styles, all the default page templates adhere to a common ID structure, which is reasonably self explanatory if you know HTML/CSS.


Site dimensions
You can customize the widths, paddings and margins of your custom theme. However, in a two column layout, the left column should have a minimum of 660px, as several elements (such as video embeds) expect that width to populate properly.

As a reference, the official themes use a width of 960px. The left column is 660px and the right column is usually 240px. Generally there is 15px of padding on both sides of both columns, but this can vary a bit from theme to theme. You can also disable the sidebar on any page so it uses full width.


Available fonts
Because NationBuilder uses TypeKit, you can easily use the following high quality fonts on your website by using the font-family values below.
Chunk by Ms. Meredith Mandel.
font-family: "chunk-1","chunk-2"
Lobster by Pablo Impallari.
font-family: "lobster-1","lobster-2"
Museo Sans by exljbris Font Foundry.
font-family: "museo-sans-1","museo-sans-2"
Myriad Pro by Adobe.
font-family: "myriad-pro-1","myriad-pro-2"
Museo by exljbris Font Foundry.
font-family: "museo-1","museo-2"

Theme and page level editing
Theme level editing: There are two levels of editing your theme -- theme level editing and page level editing. Theme level describes editing entire page types and is done from the theme editor. Access the theme editor from Settings, Themes, then click New Theme or Edit next to a theme you already created. If you edit a page type here, it will impact that page type across your entire site.

Example: If you want all Petition pages on your website to look a certain way, edit the file pages_show_petition.html.

Page level editing: Page level editing is when you only want to style one specific page. Navigate to the page you want to edit from Pages, and then click Edit next to the page you want to style and then Template. Modifying the HTML and Liquid here override the theme level settings and only affect this page.

Example: You currently have a Petition page with the title “Jobs Bill” you wish to style differently than other petition pages. Click Edit next to the “Jobs Bill” page and then click Template to modify the HTML and Liquid.

Theme editor
The theme editor is where all theme files are stored, edited, parsed and previewed. Access the theme editor from Settings, Themes, then click New Theme or Edit next to a theme you already created.

Theme Settings: Define your theme name and identify the creator.

Templates: The major page, email, and activities templates you can edit. A template which has been modified will say "Yes" under the custom column. Changes to these templates will impact your entire website unless a template has been modified at the page level.

Files: Displays all files hosted for the theme selected. Click on a file to open it, or click the X button to delete it. Click on "upload files" to upload files from your computer.

New file: Create a new file using the NationBuilder editor.

Preview: Preview any page on your website before pushing it live. When working on an individual file, you can also preview it after saving a draft. Extremely useful for verifying everything looks just right before publishing it to the web.

Publish: Publishes all files to your live website.

Download: Bundles your theme into a single file to download to your computer.
Display content from one page on another page

You may want a particular page (such as your homepage) to include content from another page, such as your latest 3 blog posts. To do this, click Pages > Theme > New File and name the file _blog_latest.html, and click Create and edit file. Next, copy the following contents into the file and click Save and Publish.

The code above was pulled from the blog template, and will display the latest 3 posts, and truncate each post to 50 characters each. Adjust or restyle this as you desire.

Note: To display content from other page types, copy and paste the for statement from the template of that page type into the new file instead of the code above.

Next, click Pages and then Edit next to the page where you wish to display the posts. Then click Template, and paste the following where you want the posts to display:

This is using the page with the slug blog and the partial template _blog_latest.html. You can apply this technique with other pages as well. Just adjust the partial template and {% subpage %} tag to match what you wish to display.


Display pages with a certain tag on another page

While clicking on page tag will display all pages with that tag, you may want to include pages with the same tag on another page. Doing this is very similar to the method listed above.

For example, let's say you wanted to include all blog posts with the tag "California" on a basic page. To do this, click Pages > Theme > New File and name the file something like _ca_posts.html, and click Create and edit file. Next, copy the following contents into the file and click Save and Publish.

This will display the latest 5 blog posts. Adjust as you desire.

Next, click Pages and then Edit next to the page where you wish to display the posts tagged California. Then click Template, and paste the following where you want the posts to display:

This will use the ca_posts.html file we first created and populate it with all the blog posts tagged California.

Note: Always use lower case letters for the tag in the code above. If your tag is more than one word, use an underscore instead of a space.

Do you like this page?

Showing 10 reactions


cStreet Campaigns commented 2012-04-28 21:25:42 -0700
Hey Jay – Navigate to where Jesse recommended then find this block of code:

#content_wrap_background {
border-top: 1px solid darken($theme_color_6, 11);
background: transparent;
padding: 0; }

and replace with:

#content_wrap_background {
border-top: 1px solid darken($theme_color_6, 11);
background: transparent;
opacity: 0.8;
padding: 0; }

you can play with the “opacity” number to find the desired level.
Jay Smythe commented 2012-04-28 19:32:21 -0700
Thanks again Jesse!
Jesse Haff commented 2012-04-28 19:02:56 -0700
When viewing theme.scss, click on the Default button. That will reveal all the styles being imported by the theme you cloned. The second window down is most likely where you’ll find what you’re looking for. If you need more help, feel free to email us at help at nationbuilder dot com. Thanks!
Jay Smythe commented 2012-04-28 10:20:52 -0700
Thanks Jesse! I got that far, but now I’m actually having a hard time locating where to override from ‘Theme.scss > Defaults’.
Jesse Haff commented 2012-04-24 14:42:29 -0700
You can do that by modifying your theme.scss and theme template files. To access those, you will need to click Pages > Theme > New custom theme, and leave “Clone your current theme” and “Switch to your new site them immediately” checked.
Jay Smythe commented 2012-04-24 14:38:04 -0700
Hi! I’ve searched the documentation but can’t find a way to change the page background opacity. I’d like to customize the Cascade official theme so that blog posts (and all other page types for that matter) have an opacity similar to the Focus official theme. Possible?
Marjorie Roswell commented 2011-11-17 06:32:15 -0800
Thanks!
Jim Gilliam commented 2011-11-17 05:06:31 -0800
We need to update the screencast, but the defaults for all stylesheets and templates are available when you are editing the file in the control panel by clicking on “default”
Marjorie Roswell commented 2011-11-17 01:37:07 -0800
Key section at 04:46 not working for me. When I try it myself, I don’t get that sidebar with the link to Overriding Theme Styles. (there’s no sidebar at all.) I do see a text link to objects and variables, but unfortunately, still no link to “Overriding Theme Styles.”
Marjorie Roswell commented 2011-11-17 01:26:21 -0800
Around 12:30, I think you meant “6,” not “12.”
Loading

Theme documentation

Object reference