In Visual Studio, open the Package Manager Console and run:

Install-Package ButterCMS

The source is available on Github. We also have a .NET Core Boiler Plate CMS project as well.

Set your API token:

var apiToken = "your_api_token";

Create an API client object:

using ButterCMS;
var client = new ButterCMSClient(apiToken);

Run this:

var response = client.ListPosts(1, 10);

You can inspect the response variable in the debugger to see the results. This API request fetches our blog posts. Your account comes with one example post which you'll see in the response. If you get a response it means you're now able to connect to our API.

Contents

Headless CMS

ButterCMS is a headless CMS that lets you manage content using our dashboard and integrate it into your tech stack of choice with our content APIs. You can use ButterCMS for new projects as well as add it to existing codebases.

If you're familiar with Wordpress, see how ButterCMS compares to WordPress.

ButterCMS provides a user-friendly UI for managing marketing sites, blogging, and custom content scenarios. We can be used for SEO landing pages, customer case studies, company news & updates, events + webinar pages, education center, location pages, knowledgebases, and more.

We are different from a traditional CMS like Drupal or Wordpress in that we're not a large piece of software you need to download, host, customize, and maintain. Instead we provide easy to consume, performant content API's that you add to your application.

For example, if you wanted to enable a non-technical person to be able to add customer case study pages to your marketing site, you might create a Case Study Page Type to represent these pages. The non-technical person would be able to manage these pages from our dashboard and the JSON API output would look something like this:

{  
  "data": {
    "slug": "acme-co-case-study",
    "page_type": "case_study",
    "fields": {
      "seo_title": "Acme Co Customer Case Study",
      "seo_description": "Acme Co saved 200% on Anvil costs with ButterCMS",
      "title": "Acme Co loves ButterCMS",
      "body": "<p>We've been able to make anvils faster than ever before! - Chief Anvil Maker</p>"
    }
  }
}

Use Postman to experiment

Postman is a great tool for experimenting with our API. We wrote a post about it here. Once you've installed Postman, click this button to quickly add our end point Collection to your Postman.

Run in Postman

Write API

We have a Write / POST API that allows you to programmatically create content. This can enable many powerful use cases and allow you to scale your content faster than ever.

Refer to our Write API Documentation to learn more.

Our Write API is available in our Enterprise plan and you will need to use a write-enabled token which is provided on request. Just contact us via email or livechat to get yours.

Webhooks

Webhooks are a powerful feature that allow you to notify your internal systems whenever content in ButterCMS has changed. You can learn more about Webhooks in this blog post.

Image Transformation

ButterCMS has integrated with a rich image transformation API called Filestack. This allows you to modify your uploaded images in dozens of ways. Everything from resizing, cropping, effects, filters, applying watermarks and more. Check out Filestack full documentation for more detail.

After you upload an image to ButterCMS, it's stored on our CDN. To create a thumbnail, here's an example:

Original URL = https://cdn.buttercms.com/zjypya5tRny63LqhHQrv

Thumbnail URL = https://fs.buttercms.com/resize=width:200,height:200/zjypya5tRny63LqhHQrv

Resizing is just one of the many different transformations you can do to your images. Refer to the Filestack docs for full details.

Localization

ButterCMS has full support for localization of your content. Locale names and keys are completely customizable and there's no limit to the number of locales you can have. View our API Reference to learn how to query by locale.

Table of Contents

Introduction

Quickly launch a new marketing site or add CMS-powered pages to your existing site using our Pages.

Create a Single Page

Adding a CMS-powered page to your app involves three easy steps:

  1. Create the Page structure
  2. Populate the content
  3. Integrate into your application

If you need help after reading this, contact us via email or livechat.

Create the Page Structure

Create a new Page and define it's structure using our Page Builder. Let's create an example homepage.

PagesNewSinglePage

Populate the Content

Then populate our new page with content. In the next step, we'll call the ButterCMS API to retrieve this content from our app.

PagesNewSinglePageContent

Integrate into your application

With your homepage defined, the ButterCMS Pages API will return it in JSON format like this:

{
  "data": {
    "slug": "homepage",
    "page_type": null,
    "fields": {
      "seo_title": "Anvils and Dynamite | Acme Co",
      "headline": "Acme Co provides supplies to your favorite cartoon heroes.",
      "hero_image": "https://cdn.buttercms.com/c8oSTGcwQDC5I58km5WV",
      "call_to_action": "Buy Now",
      "customer_logos": [
        {
          "logo_image": "https://cdn.buttercms.com/c8oSTGcwQDC5I58km5WV"
        },
        {
          "logo_image": "https://cdn.buttercms.com/c8oSTGcwQDC5I58km5WV"
        }
      ]
    }
  }
}

To integrate this into your app, create a route that fetches content for the page:

Controllers/HomeController.cs:

using System.Threading.Tasks;
using System.Web.Mvc;
using ButterCMS;
using Newtonsoft.Json;

public namespace ButterCmsExample
{
    public class Homepage
    {
        public string seo_title { get; set; }
        public string headline { get; set; }
        public string hero_image { get; set; }
        public string call_to_action { get; set; }
        public List<string> customer_logos { get; set; }
    }

    public class HomeController : Controller
    {
        [Route("/")]
        public async Task<ActionResult> ShowHome()
        {
          var butterClient = new ButterCMSClient("your_api_token");

          PageResponse<Homepage> home = butterClient.RetrievePage<Homepage>("*", "homepage");

          var viewModel = new HomeViewModel();
          viewModel.SeoTitle = home.Data.Fields.seo_title
          viewModel.Headline = home.Data.Fields.headline
          viewModel.HeroImage = home.Data.Fields.hero_image
          viewModel.CallToAction = home.Data.Fields.call_to_action
          viewModel.CustomerLogos = home.Data.Fields.customer_logos

          return View(viewModel);
        } 
    }

    public class HomeViewModel
    {
        public string SeoTitle { get; set; }
        public string Headline { get; set; }
        public string HeroImage { get; set; }
        public string CallToAction { get; set; }
        public List<string> CustomerLogos { get; set; }
    }
    
}

Views/Home.cshtml:

@using ButterCmsExample
@{
Layout = "~/Views/Shared/Layouts/_Layout.cshtml";
}
@model HomeViewModel
<html>
  <head>
    <title>@{Model.SeoTitle}</title>
  </head>
  <body>
    <h1>@{Model.Headline}</h1>
    <img width="100%" src="@{Model.HeroImage}">
    <button>@{Model.CallToAction}</button>
    <h3>Our Customers Love Us!</h3>
    <!-- Loop over customer logos -->
    @{Model.CustomerLogos}
  </body>
</html>

That's it! If you browse to your homepage you'll see your homepage populated with the content you created in Butter.

Create multiple pages using Page Types

Overview Video

Let's say you want to add a set of customer case study pages to your marketing site. They all have the same structure but the content is different. Page Types are perfect for this scenario and involves three easy steps:

  1. Create the Page Type structure
  2. Populate the content
  3. Integrate into your application

If you need help after reading this, contact us via email or livechat.

Create the Page Type structure

Create a Page Type to represent your Customer Case Study pages:

PagesNewPageType1

After saving, return to the configuration page by clicking the gear icon:

PagesNewPageType2

Then click on Create Page Type and name it "Customer Case Study". This will allow us to reuse this field configuration across multiple customer case study pages:

PagesNewPageType3

Populate the Content

Then populate our new page with content. In the next step, we'll call the ButterCMS API to retrieve this content from our app.

PagesNewSinglePageContent

Integrate into your application

This guide uses C# with Microsoft's MVC web framework but Butter integrates with any .NET web app. With your page defined, the ButterCMS API will return it in JSON format like this:

{  
  "data": {
    "slug": "acme-co-case-study",
    "page_type": "case_study",
    "fields": {
      "seo_title": "Acme Co Customer Case Study",
      "seo_description": "Acme Co saved 200% on Anvil costs with ButterCMS",
      "title": "Acme Co loves ButterCMS",
      "body": "<p>We've been able to make anvils faster than ever before! - Chief Anvil Maker</p>"
    }
  }
}

To create these pages in our app, we create a route that fetches content for the page by using a URL slug parameter:

Controllers/HomeController.cs:

using System.Threading.Tasks;
using System.Web.Mvc;
using ButterCMS;
using Newtonsoft.Json;

public namespace ButterCmsExample
{
    public class CaseStudyPage
    {
        public string facebook_open_graph_title { get; set; }
        public string seo_title { get; set; }
        public string headline { get; set; }
        public string testimonial { get; set; }
        public string customer_logo { get; set; }
    }

    public class CaseStudyController : Controller
    {
        [Route(customers/)]
        public virtual ActionResult Index(int page = 1, int pageSize = 10)
        {
            var butterClient = new ButterCMSClient("API KEY");

            var parameterDict = new Dictionary<string, string>()
            {
                {"page", page.ToString()},
                {"page_size", pageSize.ToString()}
            };

            PagesResponse<CaseStudyPage> caseStudyPages = butterClient.ListPages<CaseStudyPage>("customer_case_study", parameterDict);

            var viewModel = new CaseStudiesViewModel();
            viewModel.PreviousPageNumber = caseStudyPages.Meta.PreviousPage;
            viewModel.NextPageNumber = caseStudyPages.Meta.NextPage;
            viewModel.PagesCount = caseStudyPages.Meta.Count;

            viewModel.CaseStudies = new List<CaseStudyViewModel>();
            foreach (Page<CaseStudyPage> caseStudy in caseStudyPages.Data)
            {
                CaseStudyViewModel caseStudyViewModel = new CaseStudyViewModel();

                caseStudyViewModel.FacebookOGTitle = caseStudy.Data.Fields.facebook_open_graph_title;
                caseStudyViewModel.SeoTitle = caseStudy.Data.Fields.seo_title;
                caseStudyViewModel.Headline = caseStudy.Data.Fields.headline;
                caseStudyViewModel.Testimonial = caseStudy.Data.Fields.testimonial;
                caseStudyViewModel.CustomerLogo = caseStudy.Data.Fields.customer_logo;

                viewModel.CaseStudies.Add(caseStudyViewModel);
            }

            return View(viewModel);
        }


        [Route(customers/{slug})]
        public virtual ActionResult ShowCaseStudy(string slug)
        {
            var butterClient = new ButterCMSClient("your_api_token");

            PageResponse<CaseStudyPage> caseStudy = butterClient.RetrievePage<CaseStudyPage>("customer_case_study", slug);

            var viewModel = new CaseStudyViewModel();
            viewModel.FacebookOGTitle = caseStudy.Data.Fields.facebook_open_graph_title;
            viewModel.SeoTitle = caseStudy.Data.Fields.seo_title;
            viewModel.Headline = caseStudy.Data.Fields.headline;
            viewModel.Testimonial = caseStudy.Data.Fields.testimonial;
            viewModel.CustomerLogo = caseStudy.Data.Fields.customer_logo;

            return View(viewModel);
        }
    }

    public class CaseStudiesViewModel
    {
        public List<CaseStudyViewModel> CaseStudies { get; set; }
        public int? PreviousPageNumber { get; set; }
        public int? NextPageNumber { get; set; }
        public int PagesCount { get; set; }
    }

    public class CaseStudyViewModel
    {
        public string FacebookOGTitle { get; set; }
        public string SeoTitle { get; set; }
        public string Headline { get; set; }
        public string Testimonial { get; set; }
        public string CustomerLogo { get; set; }
    }
    
}

Views/CaseStudyList.cshtml:

@using ButterCmsExample
@{
Layout = "~/Views/Shared/Layouts/_Layout.cshtml";
}
@model CaseStudiesViewModel
<div>
    <a href="/customers/?page=@{Model.PreviousPageNumber}&pageSize=10">Previous page</a>
    <a href="/customers/?page=@{Model.NextPageNumber}&pageSize=10">Next page</a>
</div>
<div>
    <p>@{Model.PagesCount} customers total</p>
</div>
<div>
    <ul>
        @foreach(var page in Model.CaseStudies)
        {
            <li>
                <a href="/customers/@{page.Slug}">@{page.Headline}
            </li>
        }
    </ul>
</div>

Views/CaseStudy.cshtml:

@using ButterCmsExample
@{
Layout = "~/Views/Shared/Layouts/_Layout.cshtml";
}
@model CaseStudyViewModel
<html>
  <head>
    <title>@{Model.SeoTitle}</title>
    <meta property="og:title" content="@{Model.FacebookOGTitle}" /> 
  </head>
  <body>
    <h1>@{Model.Headline}</h1>
    <img width="100%" src="@{Model.CustomerLogo}">
    <p>@{Model.Testimonial}</p>
  </body>
</html>

That's it! If you browse to /customers/acme-co, you'll see the Page you created in Butter.

If you need help after reading this, contact us via email or livechat.

Introduction

Collections are tables of data to be referenced by Pages, extending the use cases that you can achieve with ButterCMS. Collections can also be queried from the API directly. We'll cover example use cases of both.

Several of these use cases involve References. References are a powerful field type you can add to Pages and Collections that allow you to create links between your content.

Use Cases

Page Facets to Group/Filter By

You can use Collections as Facets (filterable properties) for your Pages. The simpliest example would be to add Categories to your Pages. Let's say you have a recipe website for different cocktails and you want to add categories to better organize these cocktail pages for your customers.

Each cocktail Page has a name, image, and ingredients:

Sample Cocktail Page

Here's what the API JSON response looks like for your cocktail pages. You're going to enhance this by adding a Reference to a Category Collection.

GET https://api.buttercms.com/v2/pages/cocktails/

{
    "data": [
        {
            "slug": "old-fashioned",
            "fields": {
                "name": "Old Fashioned",
                "image": "https://cdn.buttercms.com/k4UHbZOuRhOMKw3Gys8s",
                "ingredients": "<p>1/2 tsp Sugar<br />3 dashes Angostura bitters<br />1 tsp Water<br />2 oz Bourbon</p>"
            }
        },
        {
            "slug": "martini",
            "fields": {
                "name": "Martini",
                "image": "https://cdn.buttercms.com/UKVn6r1RQSVyKoZIVeHU",
                "ingredients": "<p>2 oz. vodka</p>\n<p>1/2 oz. dry vermouth</p>\n<p>Shake ingredients with ice. Strain into a martini glass. Popular garnishes include a lemon twist and olives.</p>"
             }
        }
    ],
    meta": {
        "count": 2,
        "previous_page": null,
        "next_page": null
    }
}

To add a Category to your cocktail pages, first create a Category Collection and then configure your Collection data structure by adding Name and Slug properties to it.

Create Category Collection
Name Slug Properties To Collection

Now you can add some cocktail categories to it like Martini, Old Fashioned, etc...

Adding Items To Collection

With your Collection in place, go back to your Cocktail Page Type and add a Reference field called "Category" to the Category Collection

Adding Reference Field To Collection

Now when editing your cocktail pages, you can now categorize your cocktails.

Select a Category

These categories of course also show up in your API response your cocktails:

GET https://api.buttercms.com/v2/pages/cocktails/

{
    "data": [
        {
            "slug": "old-fashioned",
            "fields": {
                "name": "Old Fashioned",
                "image": "https://cdn.buttercms.com/k4UHbZOuRhOMKw3Gys8s",
                "ingredients": "<p>1/2 tsp Sugar<br />3 dashes Angostura bitters<br />1 tsp Water<br />2 oz Bourbon</p>",
                "category": {
                    "name": "Old Fashioned",
                    "slug": "old-fashioned"
                }
            }
        },
        {
            "slug": "martini",
            "fields": {
                "name": "Martini",
                "image": "https://cdn.buttercms.com/UKVn6r1RQSVyKoZIVeHU",
                "ingredients": "<p>2 oz. vodka</p>\n<p>1/2 oz. dry vermouth</p>\n<p>Shake ingredients with ice. Strain into a martini glass. Popular garnishes include a lemon twist and olives.</p>",
                "category": {
                    "name": "Martini",
                    "slug": "martini"
                }
             }
        }
    ],
    meta": {
        "count": 2,
        "previous_page": null,
        "next_page": null
    }
}

Naturally, now that your pages have categories, you'll want to filter your pages by category. To do this just add fields.category.slug=martini to your API query.

GET https://api.buttercms.com/v2/pages/cocktails/?&fields.category.slug=martini

{
    "data": [
        {
            "slug": "martini",
            "fields": {
                "name": "Martini",
                "image": "https://cdn.buttercms.com/UKVn6r1RQSVyKoZIVeHU",
                "ingredients": "<p>2 oz. vodka</p>\n<p>1/2 oz. dry vermouth</p>\n<p>Shake ingredients with ice. Strain into a martini glass. Popular garnishes include a lemon twist and olives.</p>",
                "category": {
                    "name": "Martini",
                    "slug": "martini"
                }
             }
        }
    ],
    meta": {
        "count": 1,
        "previous_page": null,
        "next_page": null
    }
}

To take this example further, let's say you wanted multiple Facets to organize your cocktails by. You could set up multiple Collections such as:

  • Drink Types: Cider, Colada, Cosmo, ...
  • Spirits: Bourbon, Whiskey, Gin
  • Color: Brown, Yellow, Orange

Then you would add a corresponding Reference field to link each Collection to your cocktail Pages.

This use case demonstrates is how you can use Collections to add filterable Facets to your Pages.

Reusable Promotional Page Content

There are many use cases for Collections. Another is using Collections to store reusable promotional content that can be Referenced by multiple pages. A common example is customer testimonials. You can store all of your testimonials in a Collection, then Reference those testimonials from your Pages. Here's how you'd do that:

First let's assume your marketing site has some features Pages, each focusing on a particular feature of your product or service.

ButterCMS Feature Page

Here's what the API JSON response looks like for your feature page. You're going to enhance this by adding a Reference to a Testimonials Collection.

GET https://api.buttercms.com/v2/pages/*/full-cms-feature-page

{
    "data": {
        "slug": "full-cms-feature-page",
        "fields": {
            "headline": "Powerful CMS. Zero headache.",
            "hero_image": "https://cdn.buttercms.com/RB2R32WbSxqcanOXiHYA",
            "benefits": [
                {
                    "benefit": "SEO Landing Pages"
                },
                {
                    "benefit": "Customer Case Studies"
                },
                {
                    "benefit": "Company News & Updates"
                }
            ]
        }
    }
}

Create a Collection for testimonials, each having the name of the person, their quote, a headshot, and their title + company.

Testimonials Collection

Then add your customer testimonials to your Collection.

Add Testimonials To Collection

Then add a Reference field from your feature Pages to your Testimonials Collection.

Reference to Testimonials Collection

Now you can easily add multiple testimonials to display on your marketing Pages

Selecting Testimonials From Reference

The API JSON response for your feature page now includes the testimonials you just linked.

GET https://api.buttercms.com/v2/pages/*/full-cms-feature-page

{
    "data": {
        "slug": "full-cms-feature-page",
        "fields": {
            "headline": "Powerful CMS. Zero headache.",
            "hero_image": "https://cdn.buttercms.com/RB2R32WbSxqcanOXiHYA",
            "benefits": [
                {
                    "benefit": "SEO Landing Pages"
                },
                {
                    "benefit": "Customer Case Studies"
                },
                {
                    "benefit": "Company News & Updates"
                }
            ],
            "testimonials": [
                {
                    "name": "Maggie Summers",
                    "headshot": "https://cdn.buttercms.com/iAvdwmxmSjKVfpuqPjWJ",
                    "title_company": "Sasquatch",
                    "quote": "After several attempts at implementing an open source CMS into my app, I found Butter. It’s the best!"
                },
                {
                    "name": "Drew Johnson",
                    "headshot": "https://cdn.buttercms.com/q3z0MfVTJWso2JM5IXvg",
                    "title_company": "App Partner",
                    "quote": "Wordpress was too slow and impacting our business. Butter is more performant and a faster alternative. A no brainer."
                },
                {
                    "name": "BEAU O'HARA",
                    "headshot": "https://cdn.buttercms.com/vOWy5G1LRzm60NyRd3P0",
                    "title_company": "Anstar Products",
                    "quote": "I've tried other API-first CMS'. I liked their programs, but I got yours up and running the fastest"
                }
            ]
        }
    }
}

This use case demonstrates is how you can use Collections to store reusable promotional content that can be Referenced by multiple pages.

Tables of Related Content

There are many use cases for Collections. Another is using Collections as tables of related data which you can query directly. For example let's say you want to create a music site for musicians and you want to store data like Albums and Artists. Here's how you'd model that out using Collections in Butter and then query your content.

For code examples of making API calls to query a Collection directly, check out our Collections API Reference.

First create a Collection for Arists and configure it's properties to be Name, Headshot, and Genre.

Arists Collection

Then add a few Arists to the Collection.

Add Arists To Collection

You can query Collections directly via our API. Here's what the API JSON response looks like for your Artists Collection.

GET https://api.buttercms.com/v2/content/?keys=artists

{
    "data": {
        "artists": [
            {
                "genre": "Rap",
                "name": "Drake",
                "headshot": "https://cdn.buttercms.com/V0mLWb47TaI9qmrRkzAC"
            },
            {
                "genre": "Country",
                "name": "Carrie Underwood",
                "headshot": "https://cdn.buttercms.com/FRToQffDSK2IE1O3fUuq"
            },
            {
                "genre": "Rock",
                "name": "Young the Giant",
                "headshot": "https://cdn.buttercms.com/jqVWtHf6T6acW8APrh3g"
            }
        ]
    }
}

With your Artists Collection created, you can now create a Collection for Albums which will include a Reference to our Artist Collection (every Album belongs to an Artist).

Albums Collection

Then add a few Albums.

Add Ablums To Collection

Here's what the API JSON response looks like for your Albums Collection. Note artist is a Reference the Arists Collection above.

GET https://api.buttercms.com/v2/content/?keys=albums

{
    "data": {
        "albums": [
            {
                "release_date": "2018-06-29T00:00:00",
                "artist": {
                    "genre": "Rap",
                    "name": "Drake",
                    "headshot": "https://cdn.buttercms.com/V0mLWb47TaI9qmrRkzAC"
                },
                "cover_art": "https://cdn.buttercms.com/uorkxsTQfit8N8uW6Im4",
                "album_name": "Scorpion"
            },
            {
                "release_date": "2018-09-14T00:00:00",
                "artist": {
                    "genre": "Country",
                    "name": "Carrie Underwood",
                    "headshot": "https://cdn.buttercms.com/FRToQffDSK2IE1O3fUuq"
                },
                "cover_art": "https://cdn.buttercms.com/3m0oGGyXQNCUnQke4Ps5",
                "album_name": "Cry Pretty"
            },
            {
                "release_date": "2018-10-12T00:00:00",
                "artist": {
                    "genre": "Rock",
                    "name": "Young the Giant",
                    "headshot": "https://cdn.buttercms.com/jqVWtHf6T6acW8APrh3g"
                },
                "cover_art": "https://cdn.buttercms.com/ThLT87lBSzyCkhivr64l",
                "album_name": "Mirror Master"
            }
        ]
    }
}

This use case demonstrates is how you can use Collections to create tables of data that Reference each other for complex content structures.

If you need help after reading this, contact us via email or livechat.

Table of Contents

Introduction

Learn how to quickly build a custom blog with great SEO. This guide uses C# with Microsoft's MVC web framework but Butter integrates with any .NET web app. Full working example code is available on Github. To get started even quicker, here's a set of sample blog templates you can use.

If you need help after reading this, contact us via email or livechat.

Install SDK

If you haven't already, you'll want to install our SDK to make querying your content from our API into your app even easier. Once you've done that, you're ready to begin setting up your blog.

Display posts

To display posts we create a simple /blog route in our app and fetch blog posts from the Butter API. See our API reference for additional options such as filtering by category or author. The response also includes some metadata we'll use for pagination.

Controllers/BlogController.cs:

public class BlogController : Controller
{
    private ButterCMSClient Client;

    private static string _apiToken = "your_api_token";

    public BlogController()
    {
        Client = new ButterCMSClient(_apiToken);
    }

    [Route("")]
    [Route("blog")]
    [Route("blog/p/{page}")]
    public async Task<ActionResult> ListAllPosts(int page = 1)
    {
        var response = await Client.ListPostsAsync(page, 10);
        ViewBag.Posts = response.Data;
        ViewBag.NextPage = response.Meta.NextPage;
        ViewBag.PreviousPage = response.Meta.PreviousPage;
        return View("Posts");
    }
}

Next we'll create a simple view at Views/Blog/Posts.cshtml that displays our posts and pagination links:

@{ 
    Page.Title = "Blog";
}

<h2>Posts</h2>

@foreach(var post in ViewBag.Posts)
{
    <a href="/blog/@Uri.EscapeDataString(post.Slug)">@post.Title</a> 
    @Html.Raw("by")
    <a href="/author/@Uri.EscapeDataString(post.Author.Slug)">@post.Author.FirstName @post.Author.LastName</a>
    <br/>
}

@if(ViewBag.PreviousPage != null)
{
    <a href="/blog/p/@ViewBag.PreviousPage">Prev</a>
}

@if(ViewBag.NextPage != null)
{
    <a href="/blog/p/@ViewBag.NextPage">Next</a>
}

We'll also create an additional route and controller method for displaying individual posts:

[Route("blog/{slug}")]
public async Task<ActionResult> ShowPost(string slug)
{
    var response = await Client.RetrievePostAsync(slug);
    ViewBag.Post = response.Data;
    return View("Post");
}

The view for displaying a full post includes information such as author, publish date, and categories. See a full list of available post properties in our API reference. We use the Page object for setting the HTML title and meta description in the <head> tag of the page.

@{ 
    Page.Title = @ViewBag.Post.SeoTitle;
    Page.MetaDescription = @ViewBag.Post.MetaDescription;
}

<h2>@ViewBag.Post.Title</h2>

Published @ViewBag.Post.Published.ToString("d/M/yyyy")
@if (@ViewBag.Post.Categories.Count > 0)
{
    @Html.Raw("in")
}
@foreach (var category in @ViewBag.Post.Categories)
{
    <a href="/category/@Uri.EscapeDataString(category.Slug)">@category.Name</a>
}

<br/>

<a href="/author/@Uri.EscapeDataString(ViewBag.Post.Author.Slug)">
    @ViewBag.Post.Author.FirstName @ViewBag.Post.Author.LastName
</a>

<br/>

<div>
    @Html.Raw(ViewBag.Post.Body)
</div>

Previewing Posts

Butter is a headless CMS, which means the design, layout, and general look & feel of your blog is controlled by your own application. As you've seen above, we return your blog content as JSON data, which you then inject into your own templates. In other words, your blog templates are just another set of templates in your app and customizing how your blog looks is the same workflow as any other page in your app. A huge benefit to this is that your blog instantly utilizes all of your existing brand CSS styling so it looks great and visually matches the rest of your app.

Because your app controls the design of your blog, Butter utilizes it to generate live previews for your content editors when they want to preview a blog post before they publish it.

Click here to configure your Blog Preview URL

To setup previewing you will need to tell Butter what your Blog's base preview URL is. i.e.:

https://yoursite.com/blog/

Once that's defined, when you preview a blog post, Butter will append the blog post slug to that preview URL and take you to:

https://yoursite.com/blog/blog-post-slug

To provide a great content editing experience, we highly recommend setting your preview URL.

Categories, Tags, and Authors

Use Butter's APIs for categories, tags, and authors to feature and filter content on your blog:

[Route("authors")]
public async Task<ActionResult> ListAllAuthors()
{
    var response = await Client.ListAuthorsAsync(false);
    ViewBag.Authors = response;
    return View("Authors");
}

[Route("author/{slug}")]
[Route("author/{slug}/p/{page}")]
public async Task<ActionResult> ShowAuthor(string slug, int page = 1)
{
    var authorResponse = await Client.RetrieveAuthorAsync(slug, false);
    var postsResponse = await Client.ListPostsAsync(page, 10, true, slug);
    ViewBag.Posts = postsResponse.Data;
    ViewBag.Author = authorResponse;
    ViewBag.NextPage = postsResponse.Meta.NextPage;
    ViewBag.PreviousPage = postsResponse.Meta.PreviousPage;
    return View("Author");
}

[Route("categories")]
public async Task<ActionResult> ListAllCategories()
{
    var response = await Client.ListCategoriesAsync(false);
    ViewBag.Categories = response;
    return View("Categories");
}

[Route("category/{slug}")]
[Route("category/{slug}/p/{page}")]
public async Task<ActionResult> ShowCategory(string slug, int page = 1)
{
    var categoryResponse = await Client.RetrieveCategoryAsync(slug, false);
    var postsResponse = await Client.ListPostsAsync(page, 10, true, null, slug);
    ViewBag.Posts = postsResponse.Data;
    ViewBag.Category = categoryResponse;
    ViewBag.NextPage = postsResponse.Meta.NextPage;
    ViewBag.PreviousPage = postsResponse.Meta.PreviousPage;
    return View("Category");
}

[Route("tags")]
public async Task<ActionResult> ListAllTags()
{
    var response = await Client.ListTagsAsync(false);
    ViewBag.Tags = response;
    return View("Tags");
}

[Route("tag/{slug}")]
[Route("tag/{slug}/p/{page}")]
public async Task<ActionResult> ShowTag(string slug, int page = 1)
{
    var tagResponse = await Client.RetrieveTagAsync(slug, false);
    var postsResponse = await Client.ListPostsAsync(page, 10, true, null, null, slug);
    ViewBag.Posts = postsResponse.Data;
    ViewBag.Tag = tagResponse;
    ViewBag.NextPage = postsResponse.Meta.NextPage;
    ViewBag.PreviousPage = postsResponse.Meta.PreviousPage;
    return View("Tag");
}

See our API reference for more information about these objects:

RSS, Atom, and Sitemap

Butter generates RSS, Atom, and sitemap XML markup. To use these on your blog, return the generated XML from the Butter API with the proper content type headers.

[Route("feeds/rss")]
public async Task<ActionResult> ShowRss()
{
    var xmlDoc = await Client.GetRSSFeedAsync();
    using (var sw = new StringWriter())
    {
        using (var xw = XmlWriter.Create(sw))
        {
            xmlDoc.WriteTo(xw);
            xw.Flush();
            return Content(sw.GetStringBuilder().ToString(), "text/xml");
        }
    }
}

[Route("feeds/atom")]
public async Task<ActionResult> ShowAtom()
{
    var xmlDoc = await Client.GetAtomFeedAsync();
    using (var sw = new StringWriter())
    {
        using (var xw = XmlWriter.Create(sw))
        {
            xmlDoc.WriteTo(xw);
            xw.Flush();
            return Content(sw.GetStringBuilder().ToString(), "text/xml");
        }
    }
}

[Route("sitemap")]
public async Task<ActionResult> ShowSitemap()
{
    var xmlDoc = await Client.GetSitemapAsync();
    using (var sw = new StringWriter())
    {
        using (var xw = XmlWriter.Create(sw))
        {
            xmlDoc.WriteTo(xw);
            xw.Flush();
            return Content(sw.GetStringBuilder().ToString(), "text/xml");
        }
    }
}

Comments

Butter doesn't provide an API for comments due to the excellent existing options that integrate easily. Two popular services we recommend are:

Both products are free, include moderation capabilities, and give your audience a familiar commenting experience. They can also provide some additional distribution for your content since users in their networks can see when people comment on your posts. For a minimalist alternative to Disqus, check out RemarkBox or for an open-source option, Isso.

Social Sharing

To maximize sharing of your content, we recommend using a free tool called AddThis.

They provide an attractive and easy to integrate social sharing widget that you can add to your website.

Social Share Buttons

CSS

Butter integrates into your front-end so you have complete control over the design of your blog. Use the following CSS as boilerplate for post content styling.

.post-container {
  h1, h2, h3, h4, h5 {
    font-weight: 600;
    margin-bottom: 1em;
    margin-top: 1.5em;
  }

  ul, ol {
    margin-bottom: 1.25em;

    li {
      margin-bottom: 0.25em;
    }
  }

  p {
    font-family: Georgia, Cambria, "Times New Roman", Times, serif;
    font-size: 1.25em;
    line-height: 1.58;
    margin-bottom: 1.25em;
    font-weight: 400;
    letter-spacing: -.003em;
  }

  /* Responsive default image width */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Responsive floating */
  @media only screen and (min-width: 720px)  {
    .butter-float-left {
      float: left;
      margin: 0px 10px 10px 0px;
    }

    .butter-float-right {
      float: right;
      margin: 0px 0px 10px 10px;
    }
  }

  /* Image caption */
  figcaption {
    font-style: italic;
    text-align: center;
    color: #ccc;
  }

  p code {
    padding: 2px 4px;
    font-size: 90%;
    color: #c7254e;
    background-color: #f9f2f4;
    border-radius: 4px;
    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
  }

  pre {
    display: block;
    padding: 1em;
    margin: 0 0 2em;
    font-size: 1em;
    line-height: 1.4;
    word-break: break-all;
    word-wrap: break-word;
    color: #333333;
    background-color: #f5f5f5;
    font-family: Menlo, Monaco,Consolas, "Courier New", monospace;
  }
}

Migration

To import content from another platform like WordPress or Medium, send us an email.

Get started now

Sign up with Google Sign up with Github
or