Loading

How to create a custom website theme

Creating a custom website theme in NationBuilder is easy to learn, and these docs cover all the essentials on how to get started. You can customize any element of your 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.

Table of contents


Create a new theme

To create a custom website theme, sign in to your nation's control panel and click Websites > Theme. This will display thumbnails of all public themes. 

public-themes.jpg

Clicking a thumbnail instantly changes the way your website looks. It also reveals several theme style variations for you to choose from which offer different colors combinations, fonts and so on.

To customize your website beyond these choices, you need to create a custom theme. To do this, click New custom theme.

theme-clone.jpg

Give your theme a name and leave Clone your current theme and Switch site to your new site immediately checked. Then click Create theme


The theme templates page

When the theme is done cloning, you will land on the templates page of your new custom theme:

templates.jpg

Some important files to note are:

  • theme.scss is the stylesheet which controls the overall look of your website. 
  • layout.html wraps every page and includes your header and footer.
  • _columns_1.html wraps the main content area of a page when the sidebar is turned off.
  • _columns_2.html wraps the main content area of a page when the sidebar is turned on.
  • splash.html wraps your splash page, if you have one enabled.

Listed below these files are templates for every type of page you can create in NationBuilder. Key points to understand about these templates are:

  • Changes made to a template here will modify every page of that type across your website. For example, modifying pages_show_blog_post.html will modify all blog posts pages. If you wish to modify a template for a specific page only, click Website, select the page you wish to edit, then click Template.
  • Templates ending in _wide.html will be shown when the sidebar is turned off on a page. 

Theme vs. 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 across your entire website. Any template edited on the themes template page accessed from Website > Theme is theme level editing.

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. Select the page you want to edit from Website and then Template. Modifying the this template will override the theme level template and only affect this page. The Files page which exists under each page is where you should upload images or assets used for that page only. 

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.

The stylesheet

Why is the stylesheet file extension .scss?

The reason the stylesheet file extension ends in .scss (instead of .css) is because NationBuilder uses the SCSS syntax of Sass. Sass is a CSS3 extension which uses mixins, variables and simple logic which allows you to do some amazing things you normally can't do with normal CSS. While you can write CSS like you always have without any problems, learning the basics of Sass can go a long way. Browse tutorials and documentation here to learn more.

Two of the most powerful features of Sass are variables and mixins. Let's take a quick look at how both work:

Variables:

Sass variables begin with a dollar sign and are followed by a value. Variables allow you to easily produce the same properties throughout your stylesheet. 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:

Now let's take a look at theme.scss. You open the file by clicking the filename theme.scss:

stylesheet.jpg

In the image above we see a color palette is defined by setting 6 color variables. This means you only need to figure out the color hex values once, and then you can easily reuse the same colors over and over again in your stylesheet.

If you scroll to the bottom of theme.scss, you'll notice there are no styles at all. Instead, you will see @import "filename". This is because all the styles are being imported from the theme you cloned. So if you cloned the Resolve theme, you will see @import "resolve";. If you click Default (located just above the template editor), you will be able to see the contents of the stylesheets being imported, including the Resolve stylesheet.

The easiest way to manipulate the way elements look on your website is to override these default styles. Using Inspect Element in Chrome and Safari or Firebug in Firefox is the easiest way to reveal which styles are controlling various areas on a given page.

For example, let's say you want to remove the white frame around your logo. First, right click on that area of the page and click Inspect Element. This will reveal the class or id name and attributes. 

inspect.jpg

You can see Inspect Element revealed the img tag, and on the right you can see that #header_pic needs to be modified in theme.scss to get rid of the border. Next, open theme.scss and make the following change:

Now click Save and publish. That's it -- the border on the logo is gone. Apply this same approach to anything you want to change on your site.


How the website templates work together

Let's take a quick look at how the website templates work by clicking on layout.html.

Layout.html is what wraps every page and includes your header and footer. Inside you'll find:

  • {{ content_for_header }} loads a critical chunk of code required for your NationBuilder website to function properly. For example, it automatically loads jQuery and relevant meta data. Never remove this.
  • {% include "nav" %}  includes the _nav.html file, which contains all the code for your top nav. You will find your _nav.html file on your theme template page if you wish to edit it.
  • {% if request.is_sidebar? %} checks to see if the sidebar is enabled on the page being loaded or not. The sidebar can be turned on or off under settings when editing any page. You will notice if the side bar is turned on, then _columns_2.html is shown, and if it's turned off, _columns_1.html is shown.
  • {{ content_for_footer }} loads a second batch of critical code required for your NationBuilder website to function properly, such as various jQuery scripts. Never remove this.

_columns_2.html wraps the main content area of a page when the sidebar is turned on. Inside you'll find:

  • {{ content_for_notifications }} displays various notification messages, such as when a form is successfully submitted.
  • {% yield %} loads the template for the type of page being loaded. For example, if a calendar page is being loaded, the _pages_show_calendar.html template will be loaded here.
  • {% if request.logged_in? %} checks to see if the user loading the page is logged in. If they are, it loads _supporter_nav.html in the sidebar. If they aren't, it loads the rest of code in this template in the sidebar. If you want to change what is in the right column when someone is logged in, edit _supporter_nav.html.

What is shown in the sidebar changes when a user is signed in vs. signed out

If you want to change what is in the sidebar when someone is signed out, edit _columns_2.html. If you want to change what is in this area when someone is signed in, edit _supporter_nav.html. In general _columns_2.html usually includes an email sign up form, social media widgets and ways for your users to sign in, whereas _supporter_nav.html includes the sidenav which is configurable from the control panel.


Uploading images, jQuery or other assets

All images or assets used for your overall theme should be uploaded to Website > Theme > Files.

upload.jpg

When referencing images or assets in your theme templates, simply refer to them by the file name. No path is necessary. So if you upload header.jpg, refer to it like this: <img src="header.jpg"" />.

It's easy to install any jQuery script you want. From the theme templates page, click Files > Upload Files to upload all the script files. Next, click Templates > layout.html. Scroll to the bottom of the file and reference the script files somewhere above the </body> tag.

script.jpg

Depending on the installation instructions for the jQuery script you're using, you may need to add additional stylesheets or javascript. If so, the same method applies.

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:

If you need to link to an absolute URL, upload the file, then right click on it and choose "Copy Link Address". That link will look something like this: https://nationslug.nationbuilder.com/assets/pages/1/filename.jpg.

If you are referencing an image or file within a <script> tag, upload the file to Website > Theme > Files and use the following code:


Image sliders

NationBuilder has a great image slider already built in. We call it a Featured content slider and you can add one to any page. Select a page you want to add it to from Website and click Featured content sliders.

slider.jpg

Simply create a label, headline and select a page to link to and then choose the image and click Save featured content slider. Repeat this process until all images you wish to use have been uploaded. You can rearrange the order of the images by drag and dropping the list on the right. 

Make sure all your images are the same size!

For your slider to look great, it's important all your featured content slider images are the exact same size. You also want them to take up the full width of the column. In most cases, a good width is 660px, but if your sidebar is disabled or if your theme uses a full width slider, you'll want a width of about 960px. If you don't have access to Photoshop, you can use apps like Gimp or even websites like picresize.com to modify the size of your images.


Fonts

Typekit

Because NationBuilder uses TypeKit, you can easily use the following high quality fonts on your website by using the font-family values below.

Please note that because Typekit restricts access to a specific domain, you will need to create your own own kit if you set up a custom domain. Learn more about registering with Typekit here.

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"

Google Web Fonts

You can also easily add free Google Web fonts to your nation. Learn more about how they work and how to install them here.


Adobe Edge Web Fonts

Adobe's new free web font library can also be added to your nation easily. The edge web font library includes contributions from Adobe, Google, and other designers.


Display content from one page on another page

You may want your homepage to include snippets of content from another page, such as your latest 3 blog posts. To do this, click Website > Theme > New File and name the file _blog_latest.html, and click Create and edit file. Next, copy and paste 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 Website and then select the page where you wish to display the latest 3 blog 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.

You can also display an image attached to a page via this technique by using the following code:


Display content from 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 Websites > 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 Website and then select 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.


Keeping donation pages secure

Donation pages in NationBuilder automatically have SSL encryption. Users can see this by a lock icon displayed in their browser. If you want to use an image on your donation page, make sure you upload them to the Files area of the donation page as those images will be served securely. Never link to an image hosted on another server as your donation page will no longer be considered secure.


Congrats! Those are the essentials, but there's much more to learn

The documentation above explains all the essential information needed to start building our your custom website theme, but there's so much more cool stuff you can do. Dive into the how to guides below to learn about all the amazing things you can do with liquid.

Do you like this page?

Showing 16 reactions


Jennifer Conway commented 2012-12-13 14:21:53 -0800 · Flag
Is it possible to attach a thumbnail of an associated “featured image” when featuring blog posts on the homepage? I haven’t been able to find the trick. Thank you!
Eli Allen commented 2012-12-02 18:31:27 -0800 · Flag
I’d also like to post upcoming events on my homepage. I am able to pull in event posts, but can’t figure out how to limit the number of events that display or truncate the number of characters that display. Could you suggest some code for this?
Susan Low commented 2012-11-16 16:47:02 -0800 · Flag
I’d like to be able to post the next 2 events on my calendar on my home page in the same way that I was able to do the latest blog posts. Suggestions for where to get the code to just pull the calendar posts?
Jesse Haff commented 2012-05-22 09:08:17 -0700 · Flag
Wasif: If you click on the Template button when editing your homepage and check “Ignore layout template”, you can enter all the HTML for that page from scratch (including the entire header and footer content) in that template window.
Wasif Farooq commented 2012-05-22 08:28:08 -0700 · Flag
Hi . i want to create custom layout for home page only.but i can’t find any way to do this. Please help.Thanks.
Josh Stuart commented 2012-04-28 21:25:42 -0700 · Flag
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 · Flag
Thanks again Jesse!
Jesse Haff commented 2012-04-28 19:02:56 -0700 · Flag
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 · Flag
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 · Flag
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 · Flag
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 · Flag
Thanks!
Jim Gilliam commented 2011-11-17 05:06:31 -0800 · Flag
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 · Flag
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 · Flag
Around 12:30, I think you meant “6,” not “12.”