Last active
December 16, 2015 01:19
-
-
Save rsleggett/5354371 to your computer and use it in GitHub Desktop.
DD4T AutoModels example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Heading(IComponentPresentation componentPresentation) | |
{ | |
var model = ComponentViewModelBuilder.Build<HeadingViewModel>(componentPresentation.Component); | |
return View(model); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using BuildingBlocks.DD4T.MarkupModels.Nested; | |
namespace BuildingBlocks.DD4T.MarkupModels.Tests | |
{ | |
///<summary> | |
/// CarouselViewModel | |
/// Author: Robert Stevenson-Leggett | |
/// Date: 2013-04-10 | |
///</summary> | |
[TridionViewModel(SchemaTitle = "Component List")] | |
public class CarouselViewModel | |
{ | |
[TextField("title")] | |
public string Title { get; set; } | |
[NestedComponent("list", typeof(CarouselItemViewModel))] | |
public IEnumerable<CarouselItemViewModel> CarouselItemViewModels { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using DD4T.ContentModel | |
@using DD4T.Mvc.Html | |
@model Project.Web.Models.HeadingViewModel | |
@{ | |
Layout = null; | |
var componentPresentation = (IComponentPresentation)ViewContext.RouteData.Values["componentPresentation"]; | |
} | |
<article class="contextheader span3"> | |
@Html.SiteEditComponentPresentation(componentPresentation) | |
<h1 class="alignleft">@Model.TitleLine1@if(!string.IsNullOrEmpty(Model.TitleLine2)){<br/><span class="large">@Model.TitleLine2</span>} </h1> | |
@if(!string.IsNullOrEmpty(Model.ImageUrl)) | |
{ | |
<aside class="imagemasksmall alignright"> | |
<img alt="@Model.ImageAltText" src="@Model.ImageUrl"> | |
</aside> | |
} | |
@Html.Partial("_SocialPrint") | |
@if(!string.IsNullOrEmpty(Model.SubTitle)) | |
{ | |
<h3 class="darkheading">@Model.SubTitle</h3> | |
} | |
<div class="summary-text"> | |
@Model.Summary | |
</div> | |
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using BuildingBlocks.DD4T.Core.Helpers | |
@using DD4T.Mvc.Html | |
@model DD4T.ContentModel.IComponentPresentation | |
<div class="span3"> | |
@Html.SiteEditComponentPresentation(Model) | |
<article class="contextheader span2"> | |
<h1 class="alignleft">@Html.GetTextValue(Model, "title")<br> <span class="large">@Html.GetTextValue(Model, "title_line_2")</span></h1> | |
@Html.Partial("_SocialPrint") | |
<h3 class="darkheading">@Html.GetTextValue(Model, "sub_title")</h3> | |
@Html.GetTextValue(Model, "summary") | |
</article> | |
@{ | |
IHtmlString altText = new HtmlString(String.Empty); | |
IHtmlString url = new HtmlString(String.Empty); | |
Html.GetImageDetails(Model.Component, "image", out altText, out url); | |
} | |
<aside class="span1 alignright"> | |
@{ Html.GetImageDetails(Model.Component, "image", out altText, out url); } | |
@if (!string.IsNullOrWhiteSpace(url.ToString())) | |
{ | |
<div class="imagemasksmall"> | |
<img src="@url" alt="@altText" /> | |
</div> | |
} | |
@{ Html.GetImageDetails(Model.Component, "banner", out altText, out url); } | |
@if (!string.IsNullOrWhiteSpace(url.ToString())) | |
{ | |
<div> | |
<img src="@url" alt="@altText" /> | |
</div> | |
} | |
</aside> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace BuildingBlocks.DD4T.MarkupModels.Tests | |
{ | |
[TridionViewModel(SchemaTitle = "General")] | |
public class HeadingViewModel | |
{ | |
[TextField("title_line_1", InlineEditable = false)] | |
public string TitleLine1 { get; set; } | |
[TextField("title_line_2", InlineEditable = false)] | |
public string TitleLine2 { get; set; } | |
[TextField("sub_title", InlineEditable = false)] | |
public string SubTitle { get; set; } | |
[RichTextField("summary", InlineEditable = false)] | |
public string Summary { get; set; } | |
[MultimediaUrl("image")] | |
public string ImageUrl { get; set; } | |
[TextFieldComponentLink("image", "AltText", IsMetadata = true)] | |
public string ImageAltText { get; set; } | |
[TextFieldComponentLink("link","link_url")] | |
public string RelatedLinkUrl { get; set; } | |
[TextFieldComponentLink("link","link_text")] | |
public string RelatedLinkText { get; set; } | |
[BooleanField("show_social_links", IsMetadata = true)] | |
public bool ShowSocialLinks { get; set; } | |
[MultimediaUrl("thumbnail_images", IsMultiValue = true)] | |
public IEnumerable<string> ThumbnailImages { get; set; } | |
[TextField("bullet_points", InlineEditable = false, IsMetadata = true, IsMultiValue = true)] | |
public IEnumerable<string> SomeMultiValueText { get; set; } | |
[BooleanComponentLinkField("featured", "show", IsMultiValue = true)] | |
public IEnumerable<bool> CheckBoxes { get; set; } | |
[DateTimeField("publish_date")] | |
public DateTime PublishDate { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment