You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 6, 2022. It is now read-only.
WIP port of the [hijacking feature from Doc Type Grid Editor](https://github.com/skttl/umbraco-doc-type-grid-editor/blob/develop/docs/developers-guide.md#doctypegrideditorsurfacecontroller), to be used when rendering Block Lists in Umbraco.
3
3
4
-
Still very much work in progress, but to try it out, you render a block list like this:
4
+
Still very much work in progress
5
+
6
+
7
+
---
8
+
9
+
10
+
11
+
#### BlockListMvcSurfaceController
12
+
13
+
If you are not the type of developer that likes to put business logic in your views, then the ability to have a controller for you partial view is a must. To help with this, the **BlockListMvc** comes with a base surface controller you can used called `BlockListMvcSurfaceController`.
14
+
15
+
Simply create your controller inheriting from the above class, giving it a class name of `{DocTypeAlias}SurfaceController` and an action name of `{DocTypeAlias}` and then **BlockListMvc** will automatically wire it up for you and use it at render time.
16
+
17
+
```csharp
18
+
publicclassTestDocTypeSurfaceController
19
+
: BlockListMvcSurfaceController
20
+
{
21
+
publicActionResultTestDocType()
22
+
{
23
+
// Do your thing...
24
+
returnCurrentPartialView();
25
+
}
26
+
}
27
+
```
28
+
29
+
By inheriting from the `BlockListMvcSurfaceController` base class, you'll also have instant access to the following helper properties / methods.
| Model | BlockListItem | The `BlockListItem` instance of your block's data. |
34
+
| ViewPath | String | A reference to the currently configured ViewPath |
35
+
| CurrentPartialView(object model = null) | Method | Helper method to return you to the default partial view for this cell. If no model is passed in, the standard Model will be passed down. |
36
+
| PartialView(string viewName, object model = null) | Method | Helper method to return you to an alternative partial view for this cell. If no model is passed in, the standard Model will be passed down. |
37
+
38
+
---
39
+
40
+
#### Rendering using BlockListMvc
41
+
To render a `BlockListItem` using BlockListMvc, in stead of doing the usual `@Html.Partial(...)` you need to use the provided helper methods in `Our.Umbraco.BlockListMvc.Helpers`
This one returns an IHtmlString of the rendering. You can also add the list model (BlockListModel), so you can read the context of the block list item (get the index, IsLast, next/previous block etc.), and specify the viewpath with this.
45
+
46
+
Example:
47
+
5
48
```cshtml
6
49
@using Our.Umbraco.BlockListMvc.Helpers
7
50
@foreach (var block in Model.Blocks)
@@ -10,19 +53,24 @@ Still very much work in progress, but to try it out, you render a block list lik
10
53
}
11
54
```
12
55
13
-
By default, it will look in `Views/Partials/Blocks/{contentTypeAlias}.cshtml` for views, but this can be customised.
14
-
15
-
The hijacking part works just like in Dtge with the differiences being, that you have to inherit from `BlockListMvcSurfaceController` and the `Model` is `BlockListItem`. Example:
The same as the above, this one just doesn't return the HtmlString but adds the rendering to the output.
58
+
59
+
Example:
60
+
61
+
```cshtml
62
+
@using Our.Umbraco.BlockListMvc.Helpers
63
+
@foreach (var block in Model.Blocks)
64
+
{
65
+
Html.RenderBlockListItem(block, Model.Blocks)
66
+
}
24
67
```
25
68
26
-
It also adds a new [ViewPage called `BlockListItemViewPage`](https://github.com/skttl/umbraco-blocklistmvc/blob/master/src/Our.Umbraco.BlockListMvc/Mvc/BlockListItemViewPage.cs) which inherits `UmbracoViewPage` and adds a BlockContext property, from which you can get [contextual information](https://github.com/skttl/umbraco-blocklistmvc/blob/master/src/Our.Umbraco.BlockListMvc/Models/BlockListItemContext.cs) like the list the block belongs too, and whether the block is the first/last in the list etc.
69
+
---
70
+
71
+
#### Individual block views
72
+
By default, BlockListMvc will look for your block item views in Views/Partials/Blocks/{contentTypeAlias}.cshtml, but you can configure the path when rendering with BlockListItem/RenderBlockListItem.
27
73
74
+
The block view is then created like you are used to.
28
75
76
+
BlockListMvc comes with its own [ViewPage called `BlockListItemViewPage`](https://github.com/skttl/umbraco-blocklistmvc/blob/master/src/Our.Umbraco.BlockListMvc/Mvc/BlockListItemViewPage.cs) which inherits `UmbracoViewPage` and adds a BlockContext property, from which you can get [contextual information](https://github.com/skttl/umbraco-blocklistmvc/blob/master/src/Our.Umbraco.BlockListMvc/Models/BlockListItemContext.cs) like the list the block belongs too, and whether the block is the first/last in the list etc.
0 commit comments