Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

Understanding blocks

$
0
0

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

  1. 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; }
        }
  2. 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;
    }
    }
  3. Then I creata a block controller and in the index action I get data from my api and fill the block container data
  4. Then I create a partial view and then from controller pass data into the view
  5. 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?


Viewing all articles
Browse latest Browse all 9076