Imtrying to transition from the dynamic @CurrentPage to Strongly typed and Models builder in preperation for V8. I have a question about partials though. Seeing as the models builder is hooked to the document type, how do you go about using the same partial on different doc types? This would often happen, if you use doc type compositions.
For now i have it working by using the same inherits and using on both the template and partial, eg:
You have to write some logic for getting needed properties.
If aliases of properties are the same between all docTypes, you can use "Document Type Compositions", move all properties to composition and then ModelsBuilder will create an interface for you, with your properties:
Hi Alex.
Not really :), and it throws an error in the partial if i change @inherits UmbracoViewPage<ContentModels.Home> to @inherits Umbraco.Web.Mvc.UmbracoViewPage
'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Opacity' and no extension method 'Opacity' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found
"Opacity" is a doc type parameter on a doctype composition.
Models builder and partials
Imtrying to transition from the dynamic @CurrentPage to Strongly typed and Models builder in preperation for V8. I have a question about partials though. Seeing as the models builder is hooked to the document type, how do you go about using the same partial on different doc types? This would often happen, if you use doc type compositions.
For now i have it working by using the same inherits and using on both the template and partial, eg:
But what should i do, if i want to use the partial on the doctype "Textpage" as well as the the "Home" doctype?
Hi Claushingebjerg
Do not use @inherits UmbracoViewPage
You have to write some logic for getting needed properties.
If aliases of properties are the same between all docTypes, you can use "Document Type Compositions", move all properties to composition and then ModelsBuilder will create an interface for you, with your properties:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
Hope it will make sense for you.
Thanks,
Alex
Hi Alex. Not really :), and it throws an error in the partial if i change @inherits
UmbracoViewPage<ContentModels.Home>
to@inherits Umbraco.Web.Mvc.UmbracoViewPage
"Opacity" is a doc type parameter on a doctype composition.
And what is the name of your composition?
Can you share the code of all partial?
It should be:
Sure. I've changed it as i understand you. The composition is called "Sidetop"
Now throws the following error
Try this one:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
Composition name with "I" prefix.
Yup, that did the trick
Do you have any documentation on how and why it should be like this or do .net devs just know this "magic"?
Look please this article - http://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/
The models builder respects the content type's inheritance, and content type's compositions are represented by interfaces.
To see how the models are generated then you can go into ~/AppData/Models/models.generated.cs and /AppData/Models/all.generated.cs
Final question :)
How do i handle it, if i need to use the same template with 2 different doc types?
I see these ways:
GetPropertyValue method and do not use Strongly typed models at all
Composition with all used properties or parent document type
A lot of if statements with checking is there this property now or no - in other words, make templates general for document types
Hope it makes sense for you.
Thanks,
Alex
In this case number 2 or 3 makes sense as the only difference between the two doc types are internally used fields from a composition.
The doctype aliases are "Kunstner" and "importeretKunstner"
Only handles the "Kunstner" Doctype...
Seems to work, but is it the right way to do it?
Hi Claushingebjerg
As I know there is no sense to use 2 @inherits It uses only first one
This is the right way to handle compositions:
Hope it make sense
Alex
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion