@seangwright I was able to get it working that way. The only thing I haven't been successful at is passing the page into the component as a parameter in the vc: tag... something I'm missing with the "pattern matching" I think. But I was able to use the alternative approach you suggested and get the page context from within the view component itself by way of the IPageDataContextRetriever. Thanks again for sharing your insight on the PTVC pattern and helping me along the way to implementing it. Cheers! -Dave
Lead Product Evangelist @Kentico, Founding partner @craftbrewingbiz. love to learn / teach web dev & software engineering, collecting vinyl records, mowing my lawn, craft 🍺
The key to the pattern matching is to 'exit early' if the type isn't correct. That was C# will know that in the rest of the View, the type is what you expect
@model ComponentViewModel<YourPageTemplatePropertiesType>
@if (Model.Page is not YourPageType myPage)
{
return;
}
<!-- from here on, C# knows Model.Page is YourPageType and myPage is safely typecast as YourPageType --><vc:your-view-componentpage="myPage"props="Model.Properties"/>
@seangwright I was able to get it working that way. The only thing I haven't been successful at is passing the page into the component as a parameter in the vc: tag... something I'm missing with the "pattern matching" I think. But I was able to use the alternative approach you suggested and get the page context from within the view component itself by way of the IPageDataContextRetriever. Thanks again for sharing your insight on the PTVC pattern and helping me along the way to implementing it. Cheers! -Dave
Dave,
The key to the pattern matching is to 'exit early' if the type isn't correct. That was C# will know that in the rest of the View, the type is what you expect