I have tested the method of creating my own Models, and seem to be running into a number of issues.
Dll as a model mode is not used on Umbraco 8.5+.
Below i am adding a type to the contact page template. And it seems to be grabbing a old model rather than the one generated.
This would be a shame if we were to scrap the Amplify theme and create another from scratch.
Hi Alex, yes models have been rebuilt and generated multiple times and keep getting the same errors as the screenshot shown.
All im trying to do is edit a certain page. So in this case contact and add a "Article Image" as a doc type but the model is being generated and upto date but it won't let me call it unless I include that file.And including it breaks the site.
Kyle works with me, and we're running into problems with using the Amplify theme.
So using it we have followed the instructions from Amplifys download page to install the UmbracoModelsBuilder and Umbraco.ModelsBuilder.Ui even tho we are using a 8.10 version of Umbraco.
I was under the impression DLL mode was not used in Umbraco 8 anymore, so our first question is, do we still need to install Umbraco.ModelsBuilder and Umbraco.ModelsBuilder.Ui with Amplify theme? Doing so and setting it to DLL mode causes the Boot Failure. Setting it back to PureLive or AppData allows the site to come back up.
But that leads to the Model generation problem. ASP.NET Temp files are saying it cant find refrence to the generated Models.
The full version of modelsbuilder was removed from Umbraco. It's now separate nuget packages.
To use Dll mode you need to include those nuget packages. Then build models via the back office. It will just replace the generated files inside the App_Data/Models folder and compile them into the Umbraco.Web.PublishedModels.dll.
Alternatively, you can clone source code and use that, as that contains all of the code and additional functionality. Then you can decide on whatever models builder mode you want, and it will work with AppData mode.
Seems to be a roundabout situation we keep on getting into, one thing leads to another. Not sure why Amplify being referenced in the Models is not being picked up?
I think we were getting into a loop with AppData and Dll
We wanted the intellisense and i think not having the ModelsBuilder from the start was causing the problem.
So now moving the we.config to AppData generating the Models should be able to be added to the project to pick up the IntelliSense when trying to pick up the strongly typed models in our views?
Hey Matt great job with Amplify!! I have decided to have a look at it and I have 2 questions. I have used the Article/Articles as a Template for a Blog section. They are identical in that one was used as a template for the other. On my new Blog/BlogPost model I am having issues getting the Sidenav to work. It complains that model has no property for Sidenav? ie.. Model.SideNav().HasValue() generates an exception. Obviously this has something to do with models, but I seem to have no issues with any other properties in the model. Any thoughts??
I'm using the exact same Compositions as the Article Document type, in fact everything is the same. Just cannot seem to get it to recognize 'SideNav'. Any help would be appreciated.
Matt, I did extend the Models in the _Amplify.cs file to accomodate my Blogpost Model EXACTLY the same way you had the extensions setup for Article but when I include the _Amplify.cs file to make these changes I get a whole host of other compile issues and if I don't include it then it doesn't see my changes. Am I missing something else perhaps?
Installed Package Source. Here is the changed version of _Amplify.cs in the Models folder.
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
namespace Umbraco.Web.PublishedModels
{
#region IIsContentPage
public interface IIsContentPage
{
bool IsContentPage { get; set; }
}
public partial class BannerStripSection : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class BannerStripComponent : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class Gallery : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class GalleryComponent : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class ShareLinks : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class ShareLinksComponent : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class Slider : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class SliderComponent : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class UmbracoFormItem : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class UmbracoFormComponent : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class Video : IIsContentPage
{
public bool IsContentPage { get; set; }
}
public partial class VideoComponent : IIsContentPage
{
public bool IsContentPage { get; set; }
}
#endregion
public interface ISectionSettings
{
string ItemsPerRow { get; set; }
}
public interface ISideNav
{
List<(string url, string name)> SideNav();
}
public class SiteConfig
{
public AppConfig AppConfig { get; set; }
public Home Home { get; set; }
public Nav Nav { get; set; }
public Footer Footer { get; set; }
public Alert Alert { get; set; }
public Theme Theme { get; set; }
}
public partial class Article : ISectionSettings, ISideNav
{
public string ItemsPerRow { get; set; }
public AppConfig AppConfig { get; set; }
public List<(string url, string name)> SideNav()
{
var sideNav = new List<(string url, string name)>();
foreach (var content in ContentBlocks)
{
switch (content.Content.ContentType.Alias)
{
case TitleItem.ModelTypeAlias:
if (content.Content is TitleItem titleComponent)
{
sideNav.Add((titleComponent.Title.ToUrlSegment(), titleComponent.Title));
}
break;
case Markdown.ModelTypeAlias:
var markDown = content.Content as Markdown;
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
if (markDown != null) htmlDoc.LoadHtml(markDown.Content.ToString());
var h2S = htmlDoc.DocumentNode.Descendants("h2");
sideNav.AddRange(h2S.Select(h2 => (h2.InnerText.ToUrlSegment(), h2.InnerText)));
break;
}
};
return sideNav;
}
public Article Prev()
{
var prev = Siblings().SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
return prev;
}
public Article Next()
{
var siblingsReversed = Siblings().OrderBy(y => y.DisplayDate).ToList();
return siblingsReversed.SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
}
public List<Article> RelatedArticles(int take)
{
return Siblings().Where(x => x.Id != Id).OrderBy(arg => Guid.NewGuid()).Take(take).ToList();
}
private IEnumerable<Article> Siblings()
{
return this.SiblingsAndSelf().Select(x => new Article(x)).OrderByDescending(y => y.DisplayDate).ToList();
}
}
public partial class Blogpost : ISectionSettings, ISideNav
{
public string ItemsPerRow { get; set; }
public AppConfig AppConfig { get; set; }
public List<(string url, string name)> SideNav()
{
var sideNav = new List<(string url, string name)>();
foreach (var content in ContentBlocks)
{
switch (content.Content.ContentType.Alias)
{
case TitleItem.ModelTypeAlias:
if (content.Content is TitleItem titleComponent)
{
sideNav.Add((titleComponent.Title.ToUrlSegment(), titleComponent.Title));
}
break;
case Markdown.ModelTypeAlias:
var markDown = content.Content as Markdown;
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
if (markDown != null) htmlDoc.LoadHtml(markDown.Content.ToString());
var h2S = htmlDoc.DocumentNode.Descendants("h2");
sideNav.AddRange(h2S.Select(h2 => (h2.InnerText.ToUrlSegment(), h2.InnerText)));
break;
}
};
return sideNav;
}
public Blogpost Prev()
{
var prev = Siblings().SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
return prev;
}
public Blogpost Next()
{
var siblingsReversed = Siblings().OrderBy(y => y.DisplayDate).ToList();
return siblingsReversed.SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
}
public List<Blogpost> RelatedArticles(int take)
{
return Siblings().Where(x => x.Id != Id).OrderBy(arg => Guid.NewGuid()).Take(take).ToList();
}
private IEnumerable<Blogpost> Siblings()
{
return this.SiblingsAndSelf().Select(x => new Blogpost(x)).OrderByDescending(y => y.DisplayDate).ToList();
}
}
public class IconComposition
{
public string BorderColor { get; set; }
public string IconColor { get; set; }
public string FillGradient { get; set; }
}
public partial class PodsListSettings
{
public bool IsArticlePage { get; set; }
}
public partial class MiniIcon
{
public string IconColor { get; set; }
}
public partial class Nav
{
public bool AlternateNavBg { get; set; }
public string ModelAlias { get; set; }
}
public partial class Person : ISectionSettings
{
public string ItemsPerRow { get; set; }
}
public partial class PodItem
{
public string BorderColor { get; set; }
public string IconColor { get; set; }
public string FillGradient { get; set; }
}
public partial class Product : ISectionSettings
{
public string ItemsPerRow { get; set; }
public List<Product> RelatedProducts(int take)
{
return Siblings().Where(x => x.Id != Id).OrderBy(arg => Guid.NewGuid()).Take(take).ToList();
}
private IEnumerable<Product> Siblings()
{
return this.SiblingsAndSelf().Select(x => new Product(x)).ToList();
}
}
public class ShareLinkSettings
{
public string Title { get; set; }
public string TextClass { get; set; }
public bool NoColumn { get; set; }
public bool HasLargeIcons { get; set; }
public string Alignment { get; set; }
public bool IsCentered { get; set; }
}
public partial class ContactInformation
{
public string LinkClass { get; set;}
}
}
You can see the public partial class Blogpost additions I made. This may be purely a models thing since I have to have my Blogpost.generated.cs Model file included in the project for that Model to be recognized. Im using ModelsMode=AppData in the web.config but I have also tried ModelsMode=LiveAppData. Having a bear of a time with Models in general. I am working with a Nuget pkg Install of the base Umbraco 8.10.1 site. Maybe thats the issue??
You don't need to include the Models folder or any of the class files within it, it should always be excluded from the project. The only reason to include them is to help with writing your extensions.
So, exclude all the models files and make sure the project builds. Revert any changes you made to the _Amplify.cs file.
Now, make your changes to your doc types via the backoffice, I guess you have added BlogPost. So there probaly isnt anything to do there.
Now make sure the modelsbuilder mode is Dll, (you should have installed, the modelsbuilder and models builder UI nuget pacakges).
Then in the back office you click build models. This regenerates all of the generated models class files, and compiles them into the Umbraco.Web.Published models dll. So we now have the model built for blogpost. (but it's not extended yet)
Now we will add the changes you want to the models. So temporarily add the models folder to your solution (this will give you intellisense). Now make the changes to blogpost you require in the _amplify.cs file.
Save everything, now remove the models folder, we don't want this getting built (basically it acts as a blueprint for the compiled dll). The actual compilation is taken care of by running the models builder via the backoffice.
Now, go into the backoffice and build your models again. This should now pick up the extended changes and compile them into the Umbraco.Web.Published .dll.
Matt.....BRILLIANT!!! I guess the ModelBuilders was the whole issue I had all along. Nobody has taken the time to explain in detail how to get the models all synced up. Really appreciate you taking your time to explain. You Rock!!
Using my own Models not working
Hi Matt,
I have tested the method of creating my own Models, and seem to be running into a number of issues. Dll as a model mode is not used on Umbraco 8.5+. Below i am adding a type to the contact page template. And it seems to be grabbing a old model rather than the one generated.
This would be a shame if we were to scrap the Amplify theme and create another from scratch.
Running Umbraco 8.10
Hi Kyle
Did you build Models? Try to go to Umbraco backend -> Settings -> Build Models
Thanks, Alex
Hi Alex, yes models have been rebuilt and generated multiple times and keep getting the same errors as the screenshot shown.
All im trying to do is edit a certain page. So in this case contact and add a "Article Image" as a doc type but the model is being generated and upto date but it won't let me call it unless I include that file.And including it breaks the site.
Hey Alex
Kyle works with me, and we're running into problems with using the Amplify theme.
So using it we have followed the instructions from Amplifys download page to install the UmbracoModelsBuilder and Umbraco.ModelsBuilder.Ui even tho we are using a 8.10 version of Umbraco.
I was under the impression DLL mode was not used in Umbraco 8 anymore, so our first question is, do we still need to install Umbraco.ModelsBuilder and Umbraco.ModelsBuilder.Ui with Amplify theme? Doing so and setting it to DLL mode causes the Boot Failure. Setting it back to PureLive or AppData allows the site to come back up.
But that leads to the Model generation problem. ASP.NET Temp files are saying it cant find refrence to the generated Models.
The full version of modelsbuilder was removed from Umbraco. It's now separate nuget packages.
To use Dll mode you need to include those nuget packages. Then build models via the back office. It will just replace the generated files inside the App_Data/Models folder and compile them into the Umbraco.Web.PublishedModels.dll.
Alternatively, you can clone source code and use that, as that contains all of the code and additional functionality. Then you can decide on whatever models builder mode you want, and it will work with AppData mode.
Hi Matt
Ok just followed that above.
Installed Umbraco.ModelsBuilder & Umbraco.ModelBuilder.Ui into the site via NuGet and rebuilt in visual studio.
Changed to Dll mode in web.config.
Went to Generate Models in back office, then Umbraco crashes and i see the boot failed screen as above?
Can you make sure that the models in App_Data/Models are excluded from the project.
Yep, tried that, but now a new error:
Seems to be a roundabout situation we keep on getting into, one thing leads to another. Not sure why Amplify being referenced in the Models is not being picked up?
you need to exclude that models folder, I can see that it's included.
That's got it Matt.
I think we were getting into a loop with AppData and Dll
We wanted the intellisense and i think not having the ModelsBuilder from the start was causing the problem.
So now moving the we.config to AppData generating the Models should be able to be added to the project to pick up the IntelliSense when trying to pick up the strongly typed models in our views?
Okay, if you add the views folder to the solution you should have the intellisense.
Like I say though, probably best to just clone the sourcecode, so you have all of the uncompiled code.
No worries, thanks for your help on it, We'll crack on with it, and thanks again for the Amplify theme.
We'll be making a donation going forward as we'd like to use it for some up-and-coming work.
Cool, thanks, also the front-end code is also available here: https://github.com/mjbarlow/amplify-umbraco-frontend
Hey Matt great job with Amplify!! I have decided to have a look at it and I have 2 questions. I have used the Article/Articles as a Template for a Blog section. They are identical in that one was used as a template for the other. On my new Blog/BlogPost model I am having issues getting the Sidenav to work. It complains that model has no property for Sidenav? ie.. Model.SideNav().HasValue() generates an exception. Obviously this has something to do with models, but I seem to have no issues with any other properties in the model. Any thoughts??
Hey Robert
Can you share your code? A screenshot?
We've just been debugging a Block List, we may be able to help :)
Neil, It fails to recognize the definition of 'SideNav' for my Model when referencing this:
I'm using the exact same Compositions as the Article Document type, in fact everything is the same. Just cannot seem to get it to recognize 'SideNav'. Any help would be appreciated.
Ok, I might be stating the obvious here so please excuse me.
If you can re-build your Models from the Settings > ModelsBuilder and then see if it brings up the SideNav
Double-check the alias name of the SideNav you are trying to access from the Document Type / Property Type.
Then if you can load a breakpoint on the Model to see if other properties of that Document Type are being pulled through Ok?
If you want to extend the models:
https://our.umbraco.com/documentation/reference/templating/modelsbuilder/Understand-And-Extend
All custom extensions to the models are in the AppData/Models/Amplify.cs file.
Matt, I did extend the Models in the _Amplify.cs file to accomodate my Blogpost Model EXACTLY the same way you had the extensions setup for Article but when I include the _Amplify.cs file to make these changes I get a whole host of other compile issues and if I don't include it then it doesn't see my changes. Am I missing something else perhaps?
Hmm, okay, are you using the source code from github or the installed package?
Also can you put the error message you are receiving here?
Installed Package Source. Here is the changed version of _Amplify.cs in the Models folder.
using System; using System.Collections.Generic; using System.Linq; using Umbraco.Core;
namespace Umbraco.Web.PublishedModels { #region IIsContentPage public interface IIsContentPage { bool IsContentPage { get; set; } } public partial class BannerStripSection : IIsContentPage { public bool IsContentPage { get; set; } } public partial class BannerStripComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class Gallery : IIsContentPage { public bool IsContentPage { get; set; } } public partial class GalleryComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class ShareLinks : IIsContentPage { public bool IsContentPage { get; set; } } public partial class ShareLinksComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class Slider : IIsContentPage { public bool IsContentPage { get; set; } } public partial class SliderComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class UmbracoFormItem : IIsContentPage { public bool IsContentPage { get; set; } } public partial class UmbracoFormComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class Video : IIsContentPage { public bool IsContentPage { get; set; } } public partial class VideoComponent : IIsContentPage { public bool IsContentPage { get; set; } } #endregion
}
You can see the public partial class Blogpost additions I made. This may be purely a models thing since I have to have my Blogpost.generated.cs Model file included in the project for that Model to be recognized. Im using ModelsMode=AppData in the web.config but I have also tried ModelsMode=LiveAppData. Having a bear of a time with Models in general. I am working with a Nuget pkg Install of the base Umbraco 8.10.1 site. Maybe thats the issue??
Here is the error:
Okay.
You don't need to include the Models folder or any of the class files within it, it should always be excluded from the project. The only reason to include them is to help with writing your extensions.
So, exclude all the models files and make sure the project builds. Revert any changes you made to the _Amplify.cs file.
Now, make your changes to your doc types via the backoffice, I guess you have added BlogPost. So there probaly isnt anything to do there.
Now make sure the modelsbuilder mode is Dll, (you should have installed, the modelsbuilder and models builder UI nuget pacakges).
Then in the back office you click build models. This regenerates all of the generated models class files, and compiles them into the Umbraco.Web.Published models dll. So we now have the model built for blogpost. (but it's not extended yet)
Now we will add the changes you want to the models. So temporarily add the models folder to your solution (this will give you intellisense). Now make the changes to blogpost you require in the _amplify.cs file.
Save everything, now remove the models folder, we don't want this getting built (basically it acts as a blueprint for the compiled dll). The actual compilation is taken care of by running the models builder via the backoffice.
Now, go into the backoffice and build your models again. This should now pick up the extended changes and compile them into the Umbraco.Web.Published .dll.
Build your solution, now everything should work.
Matt.....BRILLIANT!!! I guess the ModelBuilders was the whole issue I had all along. Nobody has taken the time to explain in detail how to get the models all synced up. Really appreciate you taking your time to explain. You Rock!!
No worries, glad you got it working. Yeah, the whole models builder thing is a little complicated.
It's designed to give flexibility but I think it's just really confusing having all these different modes.
Again, The help is GREATLY appreciated. Now if I can figure out how to wire the Members up to AD I will be nearly home free!! Thanks again....
is working on a reply...