So I am trying to create my first block. The idea of this block is to get latest news from an api end point and then show it on different pages on the website.
What I have understood is this
- Create a block type, something like this
public class NewsBlock : BlockData { [CultureSpecific] [Display( Name = "Heading", Description = "Add a heading.", GroupName = SystemTabNames.Content, Order = 1)] public virtual String Heading { get; set; } }
- Then I create a model for my Block
public class LatestNewsViewModel { public NewsBlock NewsBlock { get; private set; } public IEnumerable<dynamic> LatestNews { get; set; } public LatestNewsViewModel(NewsBlock latestNewsBlock, IEnumerable<dynamic> latestNews) { NewsBlock = latestNewsBlock; LatestNews = latestNews; } }
- Then I creata a block controller and in the index action I get data from my api and fill the block container data
- Then I create a partial view and then from controller pass data into the view
- Then from the dashboard I can add my block where ever I want on the site
Is this the way to do it? Or am I missing something?