ps-team
10/27/2017 - 9:33 AM

Example of doing a basic Node Query and how to render the data it returns

Example of doing a basic Node Query and how to render the data it returns

<control name="News Listing Using Node Query" showInMenu="true" category="Dev Training" viewingGroup="1">
	<properties>
		<nodeQuery name="NewsArticlesQuery" orderby="Property_DatePublished desc">
			<where property="Type" operator="IsEqualTo" value="News" />
		</nodeQuery>
  </properties>
</control>

@using Contensis.Framework.Web;
@using System.Collections.ObjectModel;
@{
	ReadOnlyCollection<ContentNode> newsArticles = Properties.NewsArticlesQuery;

	if(newsArticles.Count > 0) {
		<ul>
        			@foreach(var newsArticle in newsArticles)
        			{
            			DateTime publishedDate = newsArticle.PublishedDateTime;
            	string articleTitle = newsArticle.Title;

            	<li>
                	<img src="@newsArticle.ThumbnailUrl" alt="@articleTitle" />
                	<h3><a href="@newsArticle.Path" title="@articleTitle">@articleTitle</a></h3>
                	<span>Published On: </span><time datetime="@publishedDate">@publishedDate.ToString("dd/MM/yyyy")</time>
                	<p>@newsArticle.Data.Description</p>
            	</li>
        	}
    	</ul>
	}
}