Preparing the Home Page - FadiZahhar/umbraco8showandtell GitHub Wiki
Properties:
-
heroHeading: Textstring
-
heroSubheading: Textstring
-
heroBackgroundImage: Media Picker
-
callToActionText: Textstring
-
callToActionButtonText: Textstring
-
callToActionButtonUrl: Textstring or Content Picker
-
mainNews: Multinode Picker (NewsArticle)
-
mainTweets: Textstring (for Twitter handle, e.g. "highlydeveloped")
-
Add other global fields as needed (e.g., Site Settings node as discussed earlier).
Properties:
-
title: Textstring
-
summary: Textbox
-
bodyText: Richtext Editor
-
publishDate: Date Picker
-
thumbnail: Media Picker
Properties for global use, as before.
In /Views/Partials/
you’ll use:
-
Hero.cshtml: renders hero section
-
Call To Action.cshtml: renders CTA area
-
Latest News.cshtml: renders news summary/listing
-
Latest Tweets.cshtml: renders Twitter feed (could use embed or API)
-
Footer.cshtml, NavBar.cshtml
Hero.cshtml:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
var heading = Model.Value<string>("heroHeading");
var subheading = Model.Value<string>("heroSubheading");
var backgroundImage = Model.Value<IPublishedContent>("heroBackgroundImage");
}
<section class="hero" style="background-image:url('@backgroundImage?.Url()');">
<div class="container text-center text-white">
<h1>@heading</h1>
<p class="lead">@subheading</p>
</div>
</section>
Usage:
In Home.cshtml
, render the partial:
@Html.Partial("Partials/Hero", Model)
Call To Action.cshtml:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
var text = Model.Value<string>("callToActionText");
var buttonText = Model.Value<string>("callToActionButtonText");
var buttonUrl = Model.Value<string>("callToActionButtonUrl");
}
<section class="cta text-center my-5">
<p class="lead">@text</p>
@if (!string.IsNullOrEmpty(buttonText) && !string.IsNullOrEmpty(buttonUrl)) {
<a href="@buttonUrl" class="btn btn-primary">@buttonText</a>
}
</section>
Usage:
In Home.cshtml
, render the partial:
@Html.Partial("Partials/Call To Action", Model)
-
NewsArticles.cshtml
: lists news using a filter or just a loop through all NewsArticle children. -
NewsArticle.cshtml
: displays the full content of a single article. -
Latest News.cshtml
(partial): shows a news summary (last 3 or 5 articles).
Example for Latest News:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
var news = Model.Root().DescendantsOrSelfOfType("newsArticle")
.OrderByDescending(x => x.Value<DateTime>("publishDate"))
.Take(3);
}
<section class="latest-news">
<h2>Latest News</h2>
<ul>
@foreach (var article in news) {
<li>
<a href="@article.Url">@article.Value("title")</a>
<p>@article.Value("summary")</p>
<small>@article.Value<DateTime>("publishDate"):d</small>
</li>
}
</ul>
</section>
Usage:
@Html.Partial("Partials/Latest News", Model)
a) Easiest: Twitter Widget/Embed
-
In the partial or where you want the timeline, add:
<a class="twitter-timeline" data-height="400" href="https://twitter.com/highlydeveloped?ref_src=twsrc%5Etfw">Tweets by Highly Developed</a>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
Or make it dynamic:
@{
var twitterHandle = Model.Value<string>("mainTweets") ?? "highlydeveloped";
}
<a class="twitter-timeline" data-height="400" href="https://twitter.com/@twitterHandle?ref_src=twsrc%5Etfw">Tweets by @twitterHandle</a>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
-
Place this in
Latest Tweets.cshtml
and render it in your layout or Home page.
b) Twitter Macro (Umbraco MacroPartial)
Your file: MacroPartials/Get Latest Tweets.cshtml
You can register this as a Macro in the Umbraco backoffice:
-
Go to Settings → Partial View Macro Files
-
Create new Macro, pick
Get Latest Tweets
-
Add parameters as needed (
twitterHandle
, count, etc.) -
Insert the macro in an RTE or template:
@Umbraco.RenderMacro("GetLatestTweets", new { twitterHandle = "highlydeveloped" })
c) Twitter API Integration (Advanced/Optional)
If you want to call Twitter’s API and render tweets dynamically, you need:
-
A backend C# service to fetch tweets using Twitter API (requires bearer token and setup)
-
A Partial View to render the fetched tweets
-
Ideally, a caching layer to avoid hitting API limits
You can use Tweetinvi NuGet package.
Example (pseudo-code, you’ll need to secure keys):
@functions {
IEnumerable<string> GetTweets(string handle) {
// Use Tweetinvi or HttpClient to call Twitter API and parse JSON results
// Return a list of tweet texts or objects
}
}
@{
var tweets = GetTweets("highlydeveloped");
}
<ul>
@foreach(var tweet in tweets) {
<li>@tweet</li>
}
</ul>
For production, put all API logic in a C# service/controller, not Razor, and cache the results!
@Html.Partial("Partials/Hero", Model)
@Html.Partial("Partials/Call To Action", Model)
@Html.Partial("Partials/Latest News", Model)
@Html.Partial("Partials/Latest Tweets", Model) <!-- Embed or macro as above -->
Area | Document Type | Partial View | Example Usage |
---|---|---|---|
Hero | Home | Partials/Hero | @Html.Partial("Partials/Hero", Model) |
Call to Action | Home | Partials/Call To Action | @Html.Partial("Partials/Call To Action", Model) |
News | NewsArticle | Partials/Latest News | @Html.Partial("Partials/Latest News", Model) |
Home | Partials/Latest TweetsMacroPartials/Get Latest Tweets | @Html.Partial("Partials/Latest Tweets", Model) or @Umbraco.RenderMacro("GetLatestTweets") |
With these steps and partials, you can create a modular Umbraco 8 website with a dynamic hero section, call-to-action, news, and real-time Twitter integration.
This makes your site easy to manage, scalable, and interactive for visitors.
Would you like me to provide actual code samples for Twitter API integration, or focus more on backoffice/Umbraco Macro setup for Twitter?
Or do you want a detailed step-by-step for any specific partial (news, hero, Twitter)? Just ask!