Hi,
Just wondered if this was possible.
I was just reading this: https://doc.dynamicweb.com/template-tags/introduction/other/includes-partial-views
and wondered if there is a way that we can use Partials/Includes in a .cshtml file that allows model parameters and inherits from:
@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
The guide insists that is must be a Page or Paragraph viewmodel that is inherited to allow @RenderPartial()
I am building a checkout flow (templates inside steps of the cart app), and on each page template we have several parts that ideally should be re-used as a partial and shared across all pages, but are not something we want to add into the visual editor of the cart app as they appear inside the main paragraph in various places, based on screen size.
Currently we have them rendered like this, but they differ only the variables that they need, such as a number and text
@Include("Helpers/SummarySidebar.cshtml")
I'm aware you can have variables declared in the parent razor file and these are available to the rendered HTML that is rendered as part of the Include, however this is messy and doesn't really lend itself well to re-usability. It means that each Include must have its variables rendered in the @{} tag on the parent which can be unwieldy.
It also doesn't stop compilation errors when someone takes this and puts in on another page and neglects to set the same variables required for it in the parent file that they are working in.
I can see that @Include() has an override:
public override TemplateWriter Include(string name, object model, Type modelType)
However i am unsure how to use this as i get errors during compilation and also cannot see a way to easily access the object passed in here as a model in the Included template to allow me to get the values set back out.
Whn trying to use the above overload i this gives the error System.ArgumentException: Please either set a template manager to resolve templates or add the template 'Helpers/SummarySidebar.cshtml'!
If there is a way to do this, it would be very helpful to allow us to not have to have very similar templates with different names, or mean hard coding values into each one, which is also not ideal.
Kind regards,
Joe