Help on how to start a simple website. Document Ty...
# help-with-umbraco
k
So I am just trying to recreate a simple news website with umbraco. On the main page there's a grid view with the news article images and titles etc... and when clicked on will show the news article itself. In this scenario what will i have as a document type and which as an element type? I want to only write the article once but i want to be able to use them in my homepage. Can anyone help me with this
j
Normally you'd just set them up as specific document types. So fx this node structure: Home -Articles --Article --Article ... Then make Home allowed to be in root, and allow articles to be a child of home and allow article to be a child of articles. Then on the Articles view you can call the Model.Children to get all the Article pages and loop through them and get their properties to show the preview and links You can see fx in the official starter kit package how they do it with the People page looping through its children and outputting something for each person: https://github.com/umbraco/The-Starter-Kit/blob/v11/dev/examples/Umbraco.SampleSite.Web.Legacy/Views/People.cshtml
k
Okay Thank you so much genuinely!! <3
@Jemayn Hey Jemayn. Would you know how i can get the url of an image that was from a media picker. This is a code snippit of what i have @if (featuredArticles.Any()) { @foreach (var item in featuredArticles) { @item.GetProperty("MainImage") } } else { No featured articles found. } However im not sure how i should extract the url
j
Depends what type the property MainImage is, if it's a regular media picker in Umbraco allowing only a single image, then you could call
item.Value<MediaWithCrops>("MainImage")
to get the full image model with all its data properties. To get the url without any crops or image processing you can add
.MediaUrl()
to it. But really you should have a look at the documentation for the media picker to learn more about how it can be configured and how you can render its data on the frontend: https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/media-picker-3
You should also consider using models builder for strongly typed models. Seems you are a bit new to Umbraco, I can recommend this video (and all the others in the playlist):

https://www.youtube.com/watch?v=j7RyoF_LuL0&list=PL90L_HquhD-81xTOCLLJZLl1roU6hXPhp&index=2&t=1s

k
It is a regular media picker with only one single image I try to use item.Value but it always tells me "CS8917 The delegate type could not be inferred" at the begining of my code i had done this to get the "articles" i needed from the homepage var allArticles = Model.Children.OrderBy(x => x.CreateDate); var featuredArticles = allArticles.Where(x => x.Value("isFeature")); var regularArticles = allArticles.Where(x => !x.Value("isFeature")); is this wrong?
I am new haha but okay thank you I will look into this now. If there's a simple answer to my previous question please tell me but if there isn't ill just continue with the videos now
oh wait nvm
im so sorry i was doing something wrong with the code
my apologies
this does work!
j
It's not wrong, but when you call Model.Children like that you get a list of genericly typed content nodes (the type is IPublishedContent). Which means it doesn't know anything about what kind of properties are on it. So you have to call its properties with their correct type to get them - fx the
x.Value<bool>("isFeature")
will only work if there is both a property with the alias
isFeature
and the type of property editor can be cast into a bool. If isFeature for some reason was a blocklist fx it would fail. The last link I sent you above helps to explain how you can get Umbraco to generate typed models for all document types, so you can then just do fx x.IsFeature and that property will automatically be a bool and your IDE will know that.
k
Okay thank you <3
j
Np - I will once again highyl recommend that youtube series though as it goes through a lot of very useful things 🙂 That will help you down the line
8 Views