Skip to content

Instantly share code, notes, and snippets.

@emmanueltissera
Last active December 7, 2016 08:32
Show Gist options
  • Save emmanueltissera/d7eacf43adb0eb9180ff5064ec60777e to your computer and use it in GitHub Desktop.
Save emmanueltissera/d7eacf43adb0eb9180ff5064ec60777e to your computer and use it in GitHub Desktop.
EmmTi.KenticoCloudConsumer.EnhancedDeliver Quick Setup
@model EmmTi.KenticoCloudConsumer.EnhancedDeliver.Sample.Models.SampleViewModel
<div class="article-tile article-tile-large">
<div class="col-md-12 col-lg-6">
<a href="@Url.Action("Show", "Articles", new { id = Model.System.Codename })">
<img src="@Model.TeaserImage.Url" class="article-tile-image" alt="@Model.System.Name" />
</a>
</div>
<div class="col-md-12 col-lg-6">
<div class="article-tile-date">
@Model.PostDate.ToString("m")
</div>
<div class="article-tile-content">
<h2>
<a href="@Url.Action("Show", "Articles", new { id = Model.System.Codename })">@Model.System.Name</a>
</h2>
<p class="article-tile-text lead-paragraph">
@Model.Summary
</p>
</div>
</div>
</div>
PM > Install-Package EmmTi.KenticoCloudConsumer.EnhancedDeliver
using EmmTi.KenticoCloudConsumer.EnhancedDeliver.Sample.Models;
using EmmTi.KenticoCloudConsumer.EnhancedDeliver.Factories;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace EmmTi.KenticoCloudConsumer.EnhancedDeliver.Sample.Controllers
{
public class SampleController : AsyncController
{
[Route]
public async Task<ActionResult> Index()
{
var response = await DeliverClientFactory<SampleViewModel>.GetItemAsync(SampleViewModel.ItemCodeName);
return View(response);
}
}
}
using EmmTi.KenticoCloudConsumer.EnhancedDeliver.Helpers;
using KenticoCloud.Deliver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EmmTi.KenticoCloudConsumer.EnhancedDeliver.Sample.Models
{
public class SampleViewModel : BaseContentItemViewModel
{
public const string ItemCodeName = "article";
public HtmlString BodyCopy { get; set; }
public string MetaDescription { get; set; }
public string MetaKeywords { get; set; }
public Dictionary<string, string> Personas { get; set; }
public DateTime PostDate { get; set; }
public List<SampleViewModel> RelatedArticles { get; set; }
public string Summary { get; set; }
public Asset TeaserImage { get; set; }
public string Title { get; set; }
protected override void MapContentForType(ContentItem content, int currentDepth)
{
BodyCopy = new HtmlString(content.GetString("body_copy"));
MetaDescription = content.GetString("meta_description");
MetaKeywords = content.GetString("meta_keywords");
Personas = content.GetTaxonomyItems("personas");
PostDate = content.GetDateTime("post_date");
RelatedArticles = content.GetModularContent("related_articles").GetListOfModularContent<SampleViewModel>(currentDepth + 1);
Summary = content.GetString("summary");
TeaserImage = content.GetAssets("teaser_image").FirstOrDefault();
Title = content.GetString("title");
}
}
}
<add key="DeliveryContentCacheTimeSeconds" value="300"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment