Questions & Answers block type

Questions & Answers CMS Block Type example

Rendered output of the Questions & Answers block type

Block type

Add a RekQuestionsAndAnswersBlock block type:

[SiteContentType(
    GUID = "44B4FA1B-9D89-4561-8FF6-5C64CE3D5964",
    GroupName = Globals.GroupNames.Rek,
    DisplayName = "Rek.ai Questions & Answers",
    Description = "A block that renders expandable questions and answers.")]
[SiteImageUrl("/gfx/block-type-thumbnail-rek-qna.png")]
public class RekQuestionsAndAnswersBlock : SiteBlockData // Or just BlockData if outside of Alloy
{
    [Display(
        Name = "Headertext",
        Description = "A heading that is printed above the questions.",
        Order = 1)]
    [CultureSpecific]
    public virtual string Headertext { get; set; }
 
    [Display(
        Name = "Subtree",
        Description = "The subtree to use for recommendations, if empty, the entire site is used. Ex: /science/,/accommodation/",
        Order = 2)]
    [CultureSpecific]
    public virtual string Subtree { get; set; }
 
    [Display(
        Name = "Only subpages to the currently visited page",
        Description = "Used instead of subtree and defaults to the URL of the page that is loading the block.",
        Order = 3)]
    [CultureSpecific]
    public virtual bool UseRootPath { get; set; }
 
    [Display(
        Name = "Number of hits",
        Description = "The maximum number of hits to display.",
        Order = 4)]
    [CultureSpecific]
    public virtual int Hits { get; set; }
 
    [Display(
        Name = "Advanced settings",
        Description = "Provides the opportunity to enter more parameters to the recommendation than what the interface offers. Ex: data-allowedlangs=\"se\" data-excludetree=\"/website-part-1,/website-part-2\"",
        Order = 5)]
    [CultureSpecific]
    [UIHint(UIHint.Textarea)]
    public virtual string AdvancedSettings { get; set; }
}

Block type thumbnail referenced by SiteImageUrl:

Thumbnail for the Rek.ai Questions & Answers block type

View

Add a RekQuestionsAndAnswersBlock.cshtml file to Views/Shared/Blocks:

@model RekQuestionsAndAnswersBlock
 
@{
    var attributes = new Dictionary<string, string>
    {
        { "class", "rek-prediction" },
        { "data-entitytype", "rekai-qna" }
    };
 
    if (Model.Headertext != null)
    {
        attributes.Add("data-headertext", HttpUtility.HtmlEncode(Model.Headertext));
    }
 
    if (!string.IsNullOrWhiteSpace(Model.Subtree) && !Model.UseRootPath)
    {
        attributes.Add("data-subtree", HttpUtility.HtmlEncode(Model.Subtree));
    }
    
    if (Model.UseRootPath)
    {
        attributes.Add("data-userootpath", "true");
    }
 
    if (Model.Hits > 0)
    {
        attributes.Add("data-nrofhits", Model.Hits.ToString(CultureInfo.InvariantCulture));
    }
 
    if (!isProduction
        && !string.IsNullOrWhiteSpace(siteSettings.RekProjectId)
        && !string.IsNullOrWhiteSpace(siteSettings.RekSecretKey))
    {
        attributes.Add("data-projectid", siteSettings.RekProjectId);
        attributes.Add("data-srek", siteSettings.RekSecretKey);
    }
 
    var advancedSettings = Model.AdvancedSettings != null ? " " + Model.AdvancedSettings : string.Empty;
}
 
<div @Html.Raw(string.Join(" ", attributes.Select(x => $"{x.Key}=\"{x.Value}\"")) + advancedSettings)></div>