Entry data
1
2
3
4
5
6
7
using Zengenti.Contensis.Delivery
// create the client
ContensisClient client = ContensisClient.Create();
// Get an entry
var movie = client.Entries.Get("c0798fc6-1bea-4c46-b67a-e367385704fc");
1
2
3
4
5
6
7
@movie.Id
@movie.Uri
@movie.ProjectId
@movie.ContentTypeId
@movie.DataFormat
@movie.Language
@movie.Owner
1
2
3
4
5
6
7
@movie.Version.CreatedBy
@movie.Version.Created
@movie.Version.ModifiedBy
@movie.Version.Modified
@movie.Version.PublishedBy
@movie.Version.Published
@movie.Version.VersionNo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Explicitly typed variables:
movie.Get<string>("title") // text string
movie.Get<string>("description") // text string
movie.Get<string>("content") // HTML markup
movie.Get<Image>("bannerImage") // image
movie.Get<Entry>("download") // linked entry e.g. PDF download
movie.Get<int>("revenue") // number set to integer
movie.Get<double>("revenue") // number set to decimal
movie.Get<Location>("shootLoc") // lat/lon location coordinates
movie.Get<string>("list") // single list item
movie.Get<List<string>>("listMulti") // multiple choice list
movie.Get<TaxonomyNode>("genre") // single taxonomy
movie.Get<List<TaxonomyNode>>("genres") // multi choice taxonomy
movie.Get<DateTime>("releaseDate") // single date
movie.Get<DateRange>("filmingPeriod") // date range
movie.Get<bool>("showOnHomepage") // boolean
// If in an HTML element need to be written slightly differently e.g.
<h1>@(movie.Get<string>("title"))</h1>
<p>@(movie.Get<string>("description"))</p>
// etc...
1
@Html.Raw(@movie.Get("content"))
1
2
3
4
5
6
// Get the field value as a Quote instance.
var filmQuote = movie.Get<Quote>("memorableQuote");
<blockquote cite="@filmQuote.Source">
@filmQuote.Text
</blockquote>
1
2
3
4
5
6
7
8
9
10
11
12
13
// Single selection list item
<p>@movie.Get("list")</p>
// Multiple selection list
var multiList = landing.Get<List<string>>("listMulti");
if(multiList.Count > 0)
{
<ul>
@foreach(var listItem in multiList) {
<li>@listItem</li>
}
</ul>
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Single selection taxonomy node instance
var genre = movie.Get<TaxonomyNode>("genre");
<p>@genre.Key</p> // Taxonomy Key e.g. 0/24/27
<p>@genre.Name</p> // Taxonomy Name e.g. News
// Multiple selection taxonomy node instance
var genres = landing.Get<List<TaxonomyNode>>("genres");
if(genres.Count > 0)
{
<ul>
@foreach(var item in genres){
<li>@item.Key @item.Name</li>
}
</ul>
}
// Accessing child nodes
var genre = landing.Get<TaxonomyNode>("genre");
<ul>
@foreach(var item in genre.Children){
<li>@item.Key @item.Name</li>
}
</ul>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using Zengenti.Contensis.Delivery;
// Get the field value as a Location instance.
var filmingLocation = movie.Get<Location>("filmingLocation");
// Combine lat/lng into a string.
var latLng = {{APP}}quot;{filmingLocation.Lat},{filmingLocation.Lon}";
// Use Google map API to generate a map image.
var imgUrl = "https://maps.googleapis.com/maps/api/staticmap?center="+latLng+"&zoom=14&size=400x300&sensor=false";
<div id="map">
<img src="@imgUrl" />
</div>
1
2
3
4
// Get the field value as a DateTime instance.
var releaseDate = movie.Get<DateTime>("releaseDate");
<span>@releaseDate</span>
1
2
3
4
5
6
7
8
9
// Get the field value as a DateRange instance.
var filmingPeriod = movie.Get<DateRange>("filmingPeriod");
<span class="start">@filmingPeriod.From</span>
<span class="end">@filmingPeriod.To</span>
// DateRange is a nullable DateTime so add .Value when formatting:
<span class="start">@filmingPeriod.From.Value.ToString("d MMMM yyyy")</span>
<span class="end">@filmingPeriod.To.Value.ToString("d MMMM yyyy")</span>
1
2
3
4
5
6
7
var showOnHome = movie.Get<bool>("showOnHomepage");
if(showOnHome == true)
{
<p>Yay! the entry will appear on the homepage!</p>
}
Assets - getting a file (e.g. PDF) from an entry
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Get the asset instance from the entry (single)
var download = movie.Get<Entry>("download");
// Get the asset instances from the entry (multi)
List<Entry> relatedDownloads = movie.Get<List<Entry>>("relatedFiles");
// Example use - single
<a href="@download.Uri">@download.Get("title") - @download.Properties.FileSize bytes</a>
// Example use - multiple
<ul>
@foreach(var item in relatedDownloads)
{
<li>
<a href="@item.Uri">@item.Get("title") - @item.Properties.FileSize bytes</a>
</li>
}
</ul>
1
2
3
4
5
6
@download.Id
@download.Uri
@download.ProjectId
@download.ContentTypeId
@download.DataFormat
@download.Language
1
2
@download.Properties.Filename
@download.Properties.FileSize
1
2
3
4
5
6
7
@download.Version.CreatedBy
@download.Version.Created
@download.Version.ModifiedBy
@download.Version.Modified
@download.Version.PublishedBy
@download.Version.Published
@download.Version.VersionNo
1
2
3
4
@download.Get("title")
@download.Get("description")
@download.Get("entryTitle")
@download.Get("entryDescription")
Getting an image from an entry
1
2
3
4
5
6
7
8
9
10
11
// Get the image instance from the entry
var banImg = movie.Get<Image>("bannerImage");
// Example use
<figure>
<img src="@banImg.Asset.Uri"
alt="@banImg.Asset.Get("altText")"
width="@banImg.Asset.Properties["width"]"
height="@banImg.Asset.Properties["height"]">
<figcaption>@banImg.Caption</figcaption>
</figure>
1
2
3
4
5
6
@banImg.Asset.Id
@banImg.Asset.Uri
@banImg.Asset.ProjectId
@banImg.Asset.ContentTypeId
@banImg.Asset.DataFormat
@banImg.Asset.Language
1
2
3
4
5
@banImg.Asset.Properties.Filename
@banImg.Asset.Properties.FileSize
// Width and height are extended properties so are accessed slightly differently
@banImg.Asset.Properties["width"]
@banImg.Asset.Properties["height"]
1
2
3
4
5
6
7
@banImg.Asset.Version.CreatedBy
@banImg.Asset.Version.Created
@banImg.Asset.Version.ModifiedBy
@banImg.Asset.Version.Modified
@banImg.Asset.Version.PublishedBy
@banImg.Asset.Version.Published
@banImg.Asset.Version.VersionNo
1
2
3
4
5
@banImg.Asset.Get("title")
@banImg.Asset.Get("description")
@banImg.Asset.Get("altText")
@banImg.Asset.Get("entryTitle")
@banImg.Asset.Get("entryDescription")
Composer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Get the synopsis field as a ComposedField type
var synopsis = filmEntry.Get<ComposedField>("synopsis");
<div>
@foreach(ComposedFieldItem item in synopsis)
{
// Loop through the ComposedFieldItems in the ComposedField and render the items
if (item.Type == "mainHeading")
{
<h1>@item.Value()</h1>
}
if (item.Type == "subHeading")
{
<h2>@item.Value()</h2>
}
if (item.Type == "markup")
{
<div>@Html.Raw(item.Value<string>())</div>
}
if (item.Type == "quote")
{
var filmQuote = item.Value<Quote>();
<blockquote cite="@filmQuote.Source">
@filmQuote.Text
</blockquote>
}
}
</div>
Components
1
2
3
4
5
6
7
8
9
10
// Get the component as a dynamic object
dynamic banner = movie.Get("banner");
// Text in a components
<h1>@banner.title</h1>
// Image in a component
<img src="@banner.image.Asset.Uri" alt="@banner.image.Asset.Get("altText")"
width="@banner.image.Asset.Properties["width"]"
height="@banner.image.Asset.Properties["height"]"/>
Repeating fields
1
2
3
4
5
6
7
8
9
10
11
12
// get multiple text fields
var multiText = movie.Get<List<string>>("text");
if(multiText.Count > 0)
{
<ul>
@foreach(var textItem in multiText){
<li>@textItem</li>
}
</ul>
}
Search
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using Zengenti.Contensis.Delivery
using Zengenti.Data
using Zengenti.Search
var client = ContensisClient.Create();
// create query
var query = new Query(
Op.EqualTo("sys.contentTypeId", "movie") // get all movies
);
query.OrderBy.Add("-releaseDate") // order by release date descending
query.PageIndex = 1; // start at page 1
query.PageSize = 50; // 50 items per page
// Execute the search
var results = client.Entries.Search(query);
Search an object array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using Zengenti.Contensis.Delivery
using Zengenti.Data
using Zengenti.Search
var client = ContensisClient.Create();
// create query
var query = new Query(
Op.And(
Op.EqualTo("sys.contentTypeId", "movie"), // get all movies
Op.EqualTo("categories.sys.id", "action") // With a category of action
)
);
query.OrderBy.Add("-releaseDate") // order by release date descending
query.PageIndex = 1; // start at page 1
query.PageSize = 50; // 50 items per page
// Execute the search
var results = client.Entries.Search(query);
Debugging
1
2
// output json of an object
<pre>@banner.image.Asset.ToJson()</pre>