Created
October 30, 2017 21:33
-
-
Save zealott/73fcf6ceedc7202dd9025f9aa01fc3b4 to your computer and use it in GitHub Desktop.
Demonstration of how to select and loop through a list of components while calling the appropriate partial view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Get the components, this statement gets all of them from the LeftSideColumnComponent list regardless of component type | |
| IEnumerable<ICMSElement> leftSideColumnComponents = Model.Elements(null, "LeftSideColumnComponent"); | |
| // Loop through components and call view that matches root element name. | |
| foreach (ICMSElement leftSideColumnComponent in leftSideColumnComponents) | |
| { | |
| //add a try/catch in case a view is missing | |
| String compName = leftSideColumnComponent.RootElementName; | |
| try | |
| { | |
| //If you want the component to be editable & pagebuilder compatible, put it in Editable & name it with an _Unit | |
| Html.RenderPartial("Editable/" + compName + "_Unit", leftSideColumnComponent); | |
| //otherwise they can live in components | |
| Html.RenderPartial("Components/" + compName, leftSideColumnComponent); | |
| } | |
| catch (Exception e) | |
| { | |
| // no view - output error in html comment if on runtime, or display it in designtime | |
| @(Model.IsPreview ? e.Message : "") | |
| <!-- Error displaying Editable/@compName: @e.Message--> | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment