A specific list block type

Rendered output of the list block type

Block type

Add a RekRecommendationsListBlock block type:

[SiteContentType(
    GUID = "780FAB98-D81E-483B-9B70-9FFF092E68A2",
    DisplayName = "Rek.ai List Recommendations",
    Description = "A block that displays recommendations.")]
[SiteImageUrl("/gfx/block-type-thumbnail-rek-list.png")]
public class RekRecommendationsListBlock : SiteBlockData // Or just BlockData if outside of Alloy
{
    [Display(
        Name = "Headertext",
        Description = "A heading that is printed above the recommendations. Ex: “Recommended reading”.",
        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; }
 
    [Range(1, 3)]
    [Display(
        Name = "Number of columns",
        Description = "The number of columns to render: 1,2 or 3",
        Order = 5)]
    [CultureSpecific]
    public virtual int Columns { 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 = 6)]
    [CultureSpecific]
    [UIHint(UIHint.Textarea)]
    public virtual string AdvancedSettings { get; set; }
}

Block type thumbnail referenced by SiteImageUrl:

Thumbnail for the Rek.ai List Recommendations block type

View

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

@model RekRecommendationsListBlock
 
@{
    var attributes = new Dictionary<string, string>
    {
        { "class", "rek-prediction" },
        { "data-renderstyle", "list" }
    };
 
    if (Model.Headertext != null)
    {
        attributes.Add("data-headertext", HttpUtility.HtmlEncode(Model.Headertext));
    }
 
    if (Model.Hits > 0)
    {
        attributes.Add("data-nrofhits", Model.Hits.ToString(CultureInfo.InvariantCulture));
    }
 
    if (Model.Columns > 0)
    {
        attributes.Add("data-listcols", Model.Hits.ToString(CultureInfo.InvariantCulture));
    }
 
    if (!string.IsNullOrWhiteSpace(Model.Subtree) && !Model.UseRootPath)
    {
        attributes.Add("data-subtree", HttpUtility.HtmlEncode(Model.Subtree));
    }
    
    if (Model.UseRootPath)
    {
        attributes.Add("data-userootpath", "true");
    }
 
    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>