Created
September 6, 2012 12:26
-
-
Save jhauge/3655731 to your computer and use it in GitHub Desktop.
Razor / uQuery example
This file contains hidden or 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 umbraco.NodeFactory; | |
using umbraco.interfaces; | |
namespace NyborgBy.Repositories.Entities | |
{ | |
public abstract class NodeItem | |
{ | |
protected NodeItem() | |
{ | |
} | |
protected NodeItem(INode node) | |
{ | |
Id = node.Id; | |
NodeName = node.Name; | |
NodeType = node.NodeTypeAlias; | |
Url = node.Url; | |
UrlName = node.UrlName; | |
Node = (Node) node; | |
} | |
public int Id { get; set; } | |
public string NodeName { get; set; } | |
public string NodeType { get; set; } | |
public string Url { get; set; } | |
public string UrlName { get; set; } | |
public Node Node { get; set; } | |
} | |
} |
This file contains hidden or 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
namespace NyborgBy.Repositories | |
{ | |
public class NodeRepository | |
{ | |
public static List<TeaserItem> GetTeaserItemList(string idCsv) | |
{ | |
if (string.IsNullOrWhiteSpace(idCsv)) | |
return new List<TeaserItem>(); | |
return uQuery.GetNodesByCsv(idCsv).Select(n => new TeaserItem(n)).ToList(); | |
} | |
} | |
} |
This file contains hidden or 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 Eksponent.CropUp; | |
@using NyborgBy.Repositories | |
@using NyborgBy.Repositories.Entities | |
@inherits umbraco.MacroEngines.DynamicNodeContext | |
@{ | |
var teasers = NodeRepository.GetTeaserItemList(@Model.TopTeaserSlider.ToString()); | |
} | |
@foreach (TeaserItem teaser in teasers) | |
{ | |
<div class="danehofBannerSnippet"> | |
<img src="@CropUp.GetUrl(teaser.PictureUrl, new ImageSizeArguments { CropAlias = "eventteaser" })" alt="@teaser.Header" /> | |
<div> | |
<h2>@teaser.Header</h2> | |
<p>@Html.Raw(teaser.Description)</p> | |
</div> | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not at big fan of dynamic typing and a lot of code in my razor files,
so I've devised this scheme that uses a combination of hadn coded entity
classes, a repository class and that enables me to have strongly typed
entities in my razor files, and the possibility of creating lists of entities
using uQuery methods in the repository.
This approach is only possible in VS based Umbraco projects of course.