merkle-open / NitroNetSitecore

NitroNet for Sitecore extends NitroNet with the support for the WCMS Sitecore. It handles all possible presentation scenarios to integrate a handlebars frontend into Sitecore without functional loss.
MIT License
24 stars 9 forks source link

NitroNetsitecore for view rendering. #21

Closed ssatpa closed 7 years ago

ssatpa commented 7 years ago

Can I use NitroNetSitecore for a view rendering where I want to pass a sitecore model or using glassmapper ?

daniiiol commented 7 years ago

Did you mean the possibility to pass a model to your view? If you are using a Sitecore ControllerRendering, you could execute every view with your custom model as you like.

Please read The Samples Page to get some examples about the usage of ControllerRenderings and special cases like "Model on layout level" made with the Sitecore IModelRendering.

ssatpa commented 7 years ago

Hi @daniiiol ,

No I have created a ViewRendering and want to pass a model as we do using Sitecore model

image

daniiiol commented 7 years ago

Hello @ssatpa

Yes, of course! :)

Take the example I already mentioned in my post above to create a View Rendering or see my custom code below:

SampleContact RenderingModel:

public class SampleContactModel : IRenderingModel
    {
        public string Title { get; set; }
        public void Initialize(Rendering rendering)
        {
            Title = FieldRenderer.Render(Sitecore.Context.Item, "Title");
        }
    }

And here my HBS File:

<div class="m-contact m-contact--" data-t-name="Contact">
    <div class="m-contact__title">Test: {{{Title}}}</div>
</div>

Sitecore ViewRendering configuration image

... and here my Model definition image

... aaaannd finally you should see the result in the Experience Editor of Sitecore image

Conclusion: You could use View Renderings in NitroNet.Sitecore with creation of an own RenderingModel class, derived from IRenderingModel. But, you couldn't use View Renderings and enter Sitecore-Fields directly in your Handlebars-View as like as in Razor with the Sitecore @Html.Sitecore()-Helper. For that, you need a special RenderingModelor a ControllerRendering.