How to add form in rte block and show in umbraco 1...
# help-with-umbraco
r
I am upgrading my Umbraco 10 project to 14. Previously I was using macros for rendering forms in rte but in Umbraco 14 macros have been removed now I want to show forms in rte. So if anyone has any idea about it then help me. Thanks!
j
Instead of using Macros you should use Blocks in Umbraco 14. You can find some documentation about it here: https://docs.umbraco.com/umbraco-cms/14.latest/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/rte-blocks
r
Yes I have made an element for the rte block named InsertFormsAndThems and added two properties one is the form (single form picker) and another one is the theme (theme picker) For the partial view, I made it in Views/Partials/RichText/Components/InsertFormsAndThems.cshtml Code
Copy code
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.RichTextBlockItem>
@{
    var form = Model?.Content?.Value<string>("form");
    var theme = Model?.Content?.Value<string>("theme");
}
@if (string.IsNullOrWhiteSpace(form))
{
    <h1>No form found!</h1>
}
else
{

    @(await Component.InvokeAsync("RenderForm", new { formId = Guid.Parse(form), theme = theme, includeScripts = true }))
}
And i am rendering it to the home page like this
Copy code
<partial name="/Views/Partials/RichText/Components/InsertFormsAndThems.cshtml" model="@(Model?.Value<RichTextBlockItem>("description"))" />
But now the partial view hits two times. The second time it gets a null model that throws an error and does not show any form. here is the some images of home page https://screenrec.com/share/C0vUmDfeXx https://screenrec.com/share/AlCky6qhpo
j
You say you are rendering it to the home page with the partial view. Is this correct? This block is part of the RTE, if I'm not mistaken. You add the block in the Rich-text editor, and that will render the correct partial. Maybe that is why it hits two times. It's been a while since I worked with this, so I'm not 100% sure.
r
Okay, then how to render that?
Please give me any idea how to render that rte block on my home page.
s
As the rte returns Ihtmlencoded string, I guess you could do just render it by @model.yourrteproperty (or maybe wrap it in a html.raw, don't know the syntax by heart)
r
Thanks for your reply! I have tried this when I use it as you say it hits that partial view twice with the type IPublishedContent.
12 Views