Skip to content

4. Designing a theme

Mark Downie edited this page Sep 24, 2026 · 33 revisions

DasBlog Core uses Razor views for theming. Each theme is a self-contained folder that defines the layout, post templates, and styles for the site.

In the repository, themes are stored under:

source/DasBlog.Web/Themes/<theme-name>/

At runtime, this is the application's Themes/<theme-name>/ directory.

Choose a workflow

Theme development has two common starting points:

Mode Starting point Goal
Greenfield A current built-in theme or new design requirements Create a new theme using the current DasBlog rendering model
Brownfield An existing source theme, published installation, or legacy site Preserve identity and behavior while modifying or modernizing the theme

Both workflows should use a new theme name so the original remains available until the replacement has been validated and deployed.

Available themes

DasBlog Core ships with six built-in themes:

Theme Description
dasblog Default theme, clean Bootstrap 5 layout
darkly Dark color scheme based on Bootswatch Darkly
flamingo Pink accent palette
flatly Flat, modern look based on Bootswatch Flatly (navy/blue accents)
kindofblue Blue accent palette
median Sidebar layout with summary cards (purple accents)

All built-in themes target Bootstrap 5.3 and Font Awesome 6. They are protected and cannot be edited or deleted directly. To customize a built-in theme, create a copy using the theme editor.

Theme editor

The admin panel includes a theme editor at /admin/themes for managing themes directly from the browser.

Capabilities

  • Browse themes - View all installed themes with status indicators (Active, Built-in)
  • Create theme - Copy an existing theme as a starting point for a new custom theme
  • Edit files - Edit supported text files with CodeMirror syntax highlighting
  • Versioned backups - Each save automatically creates a backup (up to 3 versions retained)
  • Revert changes - Restore a file to any previous backup version
  • Set active - Switch the site to a different theme
  • Delete - Remove custom themes (built-in themes and the active theme cannot be deleted)

Built-in themes are read-only. To customize one, create a copy first using the Create action.

Switching themes

To switch your active theme:

  1. Navigate to /admin/themes
  2. Click Set as Active on the theme you want to use

You can also change the Theme setting at /admin/settings.

Theme rendering model

The primary theme files form two rendering paths:

Display mode Page template Item template
Full post _BlogPage.cshtml _BlogItem.cshtml
Summary _BlogPageSummary.cshtml _BlogItemSummary.cshtml

_BlogPage.cshtml and _BlogPageSummary.cshtml receive a ListPostsViewModel. They normally delegate iteration to the shared _BlogItems and _BlogItemsSummary partials.

_BlogItem.cshtml and _BlogItemSummary.cshtml each receive a PostViewModel.

Full-post rendering

_BlogPage.cshtml is used for:

  • An individual blog post
  • Aggregate pages when Show item summary in aggregated views is disabled

It normally invokes _BlogItems, which renders each post with _BlogItem.cshtml.

Summary rendering

When ShowItemSummaryInAggregatedViews is enabled, aggregate views such as the home page use _BlogPageSummary.cshtml.

It normally invokes _BlogItemsSummary, which renders each post with _BlogItemSummary.cshtml.

Summary mode does not apply to an individual post page.

Note

DasBlog static pages are separate from these blog page templates. Static pages are rendered by the application view Views/BlogPost/LoadStaticPage.cshtml.

Theme folder structure

A complete theme normally contains:

File Purpose
_Layout.cshtml Master layout: HTML shell, metadata, navigation, footer, styles, and scripts
_BlogPage.cshtml Container for full post rendering
_BlogItem.cshtml Full post template
_BlogPageSummary.cshtml Container for aggregate summary rendering
_BlogItemSummary.cshtml Summary/card template for one post
custom.css Theme-specific styles
favicon.ico Optional theme favicon

A theme can also contain images, fonts, JavaScript, and overrides for application views such as Archive.cshtml, ArchiveAll.cshtml, and Category.cshtml.

JavaScript files are not loaded automatically. Reference them explicitly from _Layout.cshtml, for example:

<script src="~/theme/my-theme/custom.js" asp-append-version="true"></script>

Theme assets belong in the theme folder. Images and other files uploaded as blog-post content belong under the configured binary-content directory, normally content/binary.

Greenfield: creating a theme

Start with the current built-in theme closest to the required layout. A greenfield theme still needs the complete DasBlog template contract, authenticated controls, responsive behavior, and representative test content.

Theme editor

The recommended approach is to copy an existing theme from /admin/themes.

Command line

Create a theme based on the default dasblog theme:

dasblog-core newtheme <name>

Manually

  1. Create source/DasBlog.Web/Themes/<theme-name>/
  2. Copy the core files from an existing theme
  3. Customize the Razor views and CSS
  4. Set the theme as active at /admin/themes

Brownfield: modifying or modernizing a theme

A brownfield theme can begin in a source checkout or a published installation. Published themes are located under Themes/<theme-name>/, not source/DasBlog.Web/Themes/.

  1. Identify the active production theme.
  2. Inventory its Razor files, CSS, JavaScript, images, fonts, external dependencies, content assets, and established routes.
  3. Copy the active theme under a new name.
  4. Make incremental changes.
  5. Track changes to the theme separately from changes to content and configuration.
  6. Keep the original theme and production settings unchanged until the new theme is deployed and approved.

When modernizing a legacy theme, replace obsolete Bootstrap, Font Awesome, and third-party framework usage with current bundled equivalents. Recreate only the rules required by the design rather than carrying forward unused vendor bundles.

Previewing a theme locally

Do not replace production configuration merely to test a theme.

For source development, use an appropriate local environment configuration and run the web project:

dotnet run --project source/DasBlog.Web

For a published site, an isolated preview is safer:

  1. Copy the published installation to a temporary location.
  2. Copy the required production configuration into Preview-specific configuration files.
  3. Change the root URL and active theme only in the Preview configuration.
  4. Set ASPNETCORE_ENVIRONMENT=Preview.
  5. Bind the preview to a loopback URL such as http://127.0.0.1:5080.
  6. Copy or link the working theme into the preview.
  7. Copy changed content files when the preview does not share content.

Confirm that the Preview environment is active before relying on these files. DasBlog caches XML content, so restart the preview after changing content XML. Theme CSS and other linked assets may update without a restart.

Theme changes and content changes

Keep theme presentation and site content separate:

Change Location
Razor, CSS, JavaScript, fonts, and theme images Themes/<theme-name>/
Posts and static-page content Configured content directory
Images uploaded as post content Normally content/binary

Static-page HTML can be stored as encoded text inside .dayentry.xml. Preserve the XML encoding and parse every changed XML file before previewing or deploying it.

Use root-relative links such as /contact-us for pages on the same site. Keep external services, email links, production roots, canonical redirects, and social metadata images absolute.

Layout skeleton

New themes should use the current tag helpers and view components rather than the obsolete compatibility partials:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="@Url.Content("~/")" />

    <site-head-meta />
    <site-rss-link />
    <site-atom-link />
    <twitter-card />
    <open-graph />
    <blog-posting-schema />

    <link rel="stylesheet" href="~/lib/bootstrap/5.3.3/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/lib/font-awesome/6.7.2/css/all.css" />
    <theme-stylesheets />
</head>
<body>
    <header>
        <!-- Navigation with <site-title /> or <site-title-link /> -->
        <!-- Secure administrative controls with dasblog-authorized -->
    </header>

    <main class="container">
        <vc:cookie-consent />
        @RenderBody()
        <site-page-control view-context="@ViewContext" />
    </main>

    <footer>
        <site-copyright />
    </footer>

    <script src="~/lib/jquery/3.5.1/jquery.min.js"></script>
    <script src="~/lib/bootstrap/5.3.3/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>

    @RenderSection("scripts", required: false)
</body>
</html>

<theme-stylesheets /> loads both the shared site.css and the active theme's custom.css.

Full post template

_BlogItem.cshtml renders a full post. Because it is also used on aggregate pages when summary mode is disabled, changes to this file can affect both individual posts and the home page.

@model PostViewModel

@{
    ViewData["Title"] = Model.Title;
}

<article>
    <h1><post-title-link post="@Model" /></h1>
    <small><post-created-date post="@Model" /></small>

    <post-content post="@Model" />

    <p>
        Categories:
        <post-categories-list post="@Model">, </post-categories-list>
    </p>

    <div dasblog-authorized>
        <post-edit-link post="@Model" />
        <post-delete-link post="@Model" />
        <comment-management-link post="@Model" />
    </div>

    <vc:related-posts post="@Model" count="5" />

    <vc:collapse-comment-block post="@Model" />
</article>

The related-posts component is optional. Its location in _BlogItem.cshtml controls where it appears, and its shared CSS classes can be styled in custom.css. For complete control over the markup, add Components/RelatedPosts/Default.cshtml to the theme. See Tag Helpers & Partial Views for details.

Summary template

_BlogItemSummary.cshtml renders one compact post summary when aggregate summary mode is enabled:

@model PostViewModel

<article>
    <post-categories-list post="@Model" />
    <h2><post-title-link post="@Model" /></h2>
    <small><post-created-date post="@Model" /></small>
    <p><post-content post="@Model" strip-html="true" content-length="20" /></p>
    <post-title-link post="@Model">Continue reading...</post-title-link>
    <post-image post="@Model"
                css="card-img"
                default-image="/images/default/dasblog.svg?v=2" />
</article>

For a complete list of available tag helpers and view components, see Tag Helpers & Partial Views.

Validating a theme

  1. Check both full and summary aggregate modes.
  2. Check an individual post with a title, comments, categories, and administrative controls.
  3. Check static pages, archive pages, and category pages.
  4. Check desktop and mobile navigation and layouts.
  5. Verify theme asset paths separately from post-content asset paths.
  6. Test internal links under the local preview host.
  7. Check external embeds separately from theme rendering.
  8. Parse every changed XML content file.
  9. Confirm that the original theme and production configuration are unchanged.
  10. Build the web project:
dotnet build source/DasBlog.Web/DasBlog.Web.csproj

Deploying a theme

Prepare a deployment manifest that separates:

  1. The complete new or changed Themes/<theme-name>/ folder
  2. Changed content files and files under content/binary
  3. Intentional configuration changes
  4. The final theme activation step

Upload the theme and supporting content before setting it as active. Activate it through /admin/themes or /admin/settings after confirming all required files are present.

Additional questions?

If you have additional questions or concerns, please submit an issue.