﻿---
title: curb_razor_format_code_blocks
description: Experimental. Format the C# in @code and @functions blocks of .razor and .cshtml files, and nothing else in them. Read only from a section that names those files. Defaults to `false`
url: https://docs-v3-preview.elastic.dev/reference/razor/code-blocks/curb_razor_format_code_blocks
---

# curb_razor_format_code_blocks
Experimental. Format the C# in @code and @functions blocks of .razor and .cshtml files, and nothing else in them. Read only from a section that names those files.

## Values


| Value   | Notes |
|---------|-------|
| `true`  |       |
| `false` |       |

**Default:** `false`
Experimental. It has to be set in a section whose glob names Razor files, and `[*]`, `[**]` and `[*.*]` do not count, so a catch-all section cannot turn it on by accident:
```ini
[*.{razor,cshtml}]
curb_razor_format_code_blocks = true
```

Without it, Curb never reads a `.razor` or `.cshtml` file. With it, only the C# inside `@code` and `@functions` blocks changes: markup, `@{ }` blocks and expressions are never touched, and a block that holds Razor markup is left as written. See [Razor](https://docs-v3-preview.elastic.dev/workflow/razor).

### `curb_razor_format_code_blocks = true`

```ini
curb_razor_format_code_blocks = true
```

<tab-set>
  <tab-item title="Before">
    ```html
    @page "/counter"

    <h1>Counter</h1>
    <p role="status">Current count:   @currentCount</p>
    <button class="btn" @onclick="IncrementCount">Click me</button>

    @code {
      private int currentCount=0;

          private void IncrementCount()
      {
        currentCount+=1;
      }
    }
    ```
  </tab-item>

  <tab-item title="After">
    ```html
    @page "/counter"

    <h1>Counter</h1>
    <p role="status">Current count:   @currentCount</p>
    <button class="btn" @onclick="IncrementCount">Click me</button>

    @code {
        private int currentCount = 0;

        private void IncrementCount()
        {
            currentCount += 1;
        }
    }
    ```
  </tab-item>
</tab-set>


### `curb_razor_format_code_blocks = false`

```ini
curb_razor_format_code_blocks = false
```

<tab-set>
  <tab-item title="Before">
    ```html
    @page "/counter"

    <h1>Counter</h1>
    <p role="status">Current count:   @currentCount</p>
    <button class="btn" @onclick="IncrementCount">Click me</button>

    @code {
      private int currentCount=0;

          private void IncrementCount()
      {
        currentCount+=1;
      }
    }
    ```
  </tab-item>

  <tab-item title="After">
    ```html
    @page "/counter"

    <h1>Counter</h1>
    <p role="status">Current count:   @currentCount</p>
    <button class="btn" @onclick="IncrementCount">Click me</button>

    @code {
      private int currentCount=0;

          private void IncrementCount()
      {
        currentCount+=1;
      }
    }
    ```
  </tab-item>
</tab-set>