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 major page, email, and activities 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:

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.


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:

If you wanted to add rounded corners to elements, you can do so easily with mixins.

Mixins:

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 blog posts tagged California.

Do you like this page?

Showing 4 reactions


Marjorie Roswell commented 2011-11-17 09:32:15 -0500
Thanks!
Jim Gilliam commented 2011-11-17 08:06:31 -0500
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 04:37:07 -0500
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 04:26:21 -0500
Around 12:30, I think you meant “6,” not “12.”
Loading

Theme documentation

Object reference