---
title: Render widgets in code
related:
  - https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder.md
  - https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/widgets-for-page-builder.md
  - https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/widgets-for-page-builder/widget-properties.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Developers can display [Page Builder widgets](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/widgets-for-page-builder.md) manually, without the need to set up [editable regions](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/create-pages-with-editable-areas.md) and insert widgets in the Page Builder interface. The API allows widgets to be rendered directly in the code of views. These can be views that define the output of standard pages and layouts, or even other Page Builder components, such as [sections](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/sections-for-page-builder.md).

For example, this rendering approach can be used to include a widget into a site's main layout (the website header or footer). The widget appears as a fixed part of the website, and cannot be removed or adjusted by content editors.

## Requirements

- Page Builder must be enabled for your project, as described in [Page Builder](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder.md) (even though the widgets are rendered without the Page Builder interface).
- To allow direct rendering, widgets must be registered using the `RegisterWidget` assembly attribute (as described in [Widgets for Page Builder](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/widgets-for-page-builder.md)).
- The page where the widget is rendered must include links to [Page Builder scripts and styles](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/create-pages-with-editable-areas.md#load-page-builder-scripts-and-styles), if these are required by the given widget. The [system's default widgets](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/reference-default-page-builder-widgets.md) require the Page Builder scripts and styles.

## Render widgets

Edit the code of the view where you want to display the widget and call the `Html.Kentico().RenderStandaloneWidgetAsync` extension method (or its [Tag Helper](https://docs.kentico.com/documentation/developers-and-admins/development/reference-tag-helpers.md) equivalent).

Specify the following parameters for the method:

- `identifier` – the `string` identifier under which the widget was registered. For identifiers of the default system widgets, check [the system widget reference](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/reference-default-page-builder-widgets.md).
- `properties` – `IWidgetProperties` object representing the widget's [properties](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/widgets-for-page-builder/widget-properties.md). Create an instance of the appropriate property model class and set any required values. Currently, the properties parameter is required and you cannot render widgets without properties. As a workaround, you can create and register an empty property model for the widget.

```cshtml
@using System.Collections.Generic

@using Kentico.PageBuilder.Web.Mvc
@using Kentico.Content.Web.Mvc
@using Kentico.Web.Mvc
@using Kentico.Forms.Web.Mvc.Widgets
@using Kentico.Xperience.Admin.Base.Forms

...

@{
    // Prepares properties for the Form widget
    var widgetProperties = new FormWidgetProperties()
    {
        SelectedForm = new List<ObjectRelatedItem>() { new ObjectRelatedItem { ObjectCodeName = "FormCodeName" } },
        AfterSubmitMode = FormAfterSubmitModeConstants.DISPLAY_MESSAGE,
        AfterSubmitDisplayText = "Thank you for your input!" 
    };    
}

@* Renders the Form widget *@
@await Html.Kentico().RenderStandaloneWidgetAsync(SystemComponentIdentifiers.FORM_WIDGET_IDENTIFIER, widgetProperties); 
```

> **Info:** **Note**: Do not use the `RenderStandaloneWidgetAsync` method in the views of other widgets. If you are developing a widget that extends the HTML output or functionality of an existing widget, call the `RenderNestedWidgetAsync` extension method instead. For more information, see [Extend widgets](https://docs.kentico.com/documentation/developers-and-admins/development/builders/page-builder/widgets-for-page-builder/extend-widgets.md).
