0

Implementation: I am creating my custom SXA components for Header, Footer and Breadcrumb

I have a project "Navigation".
Under Navigation I have created three controllers Header, Breadcrumb, Footer.

I have overridden the GetModel method in each controller with their respective repositories and Views.

In VS I have a created a folder for Navigation under Views and have created three Views for Header, Breadcrumb and Footer.

Issue: I want all the three Views under on Navigation folder. So that when I publish the website the physical structure should be

  • Website
    • Views
      • Navigation
        • Header
        • Footer
        • Breadcrumb

But when the GetModel() method automatically resolves its view for each controller it is resolving to Views/ControllerName/View.chtml (Views/Footer/Footer.chtml)

Is there a way that I can create the multiple Views in the single folder and still have the different controllers resolve the respective Views under that single folder?

1
  • 1
    Curious what the requirements are that you would build custom components for those three. Head on over to the Sitecore Chat and #sxa to discuss. Mar 30, 2019 at 22:00

1 Answer 1

2

SXA has a feature that lets you easily override the default View path. It's the "Rendering View Path" field on the rendering. An example here from /sitecore/layout/Renderings/Feature/Experience Accelerator/Navigation/Navigation

SXA rendering

So in your case you can set this field to for example ~/Views/Navigation/Header.cshtml

The SXA StandardController has an Index method as follows:

public ActionResult Index()
{
    return PartialView(GetIndexViewName(), GetModel());
}

GetIndexViewName() is not a good name for what it does, it actually will first check the "Rendering View Path" field on the rendering and if that's empty it will use the "Action" on the rendering to get the view name.

Another useful feature that you might be interested in is the IsNeverLocalRendering=true which means when you drop the datasource component on the page it will ask you to create a site level data source (rather than a page level data source).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.