Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.

Commit 449a96b

Browse files
authored
Update readme.md
1 parent 6dbccc8 commit 449a96b

File tree

1 file changed

+61
-13
lines changed

1 file changed

+61
-13
lines changed

readme.md

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
11
# Our.Umbraco.BlockListMvc
22
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.
33

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+
public class TestDocTypeSurfaceController
19+
: BlockListMvcSurfaceController
20+
{
21+
public ActionResult TestDocType()
22+
{
23+
// Do your thing...
24+
return CurrentPartialView();
25+
}
26+
}
27+
```
28+
29+
By inheriting from the `BlockListMvcSurfaceController` base class, you'll also have instant access to the following helper properties / methods.
30+
31+
| Member | Type | Description |
32+
|---------------------------------------------------|-------------------|-------------|
33+
| 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`
42+
43+
##### [@Html.BlockListItem(BlockListItem item)](https://github.com/skttl/umbraco-blocklistmvc/blob/master/src/Our.Umbraco.BlockListMvc/Helpers/RenderHelper.cs#L27)
44+
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+
548
```cshtml
649
@using Our.Umbraco.BlockListMvc.Helpers
750
@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
1053
}
1154
```
1255

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:
16-
```cs
17-
public class FeatureSurfaceController : BlockListMvcSurfaceController
18-
{
19-
public ActionResult Feature()
20-
{
21-
return CurrentPartialView();
22-
}
23-
}
56+
##### [Html.RenderBlockListItem(BlockListItem item)](https://github.com/skttl/umbraco-blocklistmvc/blob/master/src/Our.Umbraco.BlockListMvc/Helpers/RenderHelper.cs#L44)
57+
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+
}
2467
```
2568

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.
2773

74+
The block view is then created like you are used to.
2875

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

Comments
 (0)