A specific pills list block type
Block type
Add a RekRecommendationsPillsBlock block type:
[SiteContentType(
GUID = "5F014AEB-EF25-4311-8C0B-207B1AF6E1B4",
GroupName = Globals.GroupNames.Rek,
DisplayName = "Rek.ai Pills Recommendations",
Description = "A block that displays recommendations as rounded buttons.")]
[SiteImageUrl("/gfx/block-type-thumbnail-rek-pills.png")]
public class RekRecommendationsPillsBlock : 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; }
[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:
View
Add a RekRecommendationsPillsBlock.cshtml file to Views/Shared/Blocks:
@model RekRecommendationsPillsBlock
@{
var attributes = new Dictionary<string, string>
{
{ "class", "rek-prediction" },
{ "data-renderstyle", "pills" }
};
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 (!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>