Try our conversational search powered by Generative AI!

Understanding blocks


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
                        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 LatestNews { get; set; }
    public LatestNewsViewModel(NewsBlock latestNewsBlock, IEnumerable 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?

Nov 08, 2017 13:02

Sound about right yes. 

5. In edit mode.

a) First create a new block in assets pane (to the right) of the new block type

b) Go to the page you want it and drag it to the content area. Publish.

Double check the parameter value in index action on block controller. Must be named currentBlock and be of correct type or you will only get null for the currentBlock. 

Edited, Nov 08, 2017 13:07

Thanks I will try now and will let you know. 

Nov 08, 2017 13:22
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.