Dear our.Umbraco.org Community
I've been working with umbraco for several weeks now and I created a "cheat-sheet" with all the important stuff I've stumbled accros during developments. I'm a genuinely nice person - therefore I decided to share this file with you. Feel free to share, extend or improve my current Code. I'm still a beginner so don't expect too much. (Tested in Umbraco 7.6.5 and partially in 7.6.6)
_____________
Make a Redirect to Umbraco Login page on Startup for security reasons
(Copy This code into Master.cshtml)
@using Umbraco.Core.Security;
var userTicket = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
if (userTicket == null)
{
Response.Redirect("~/umbraco");
}
Get Image out of normal Media library
bool hasImage = Model.Content.HasValue("image");
var image = "";
if (hasImage)
{
var mediaObject = Convert.ToString(Model.Content.GetPropertyValue("image"));
int mediaIDimage = Convert.ToInt16(mediaObject);
image = Umbraco.Media(mediaIDimage).Url;
}
If (hasImage)
{
<img src=“@image“ …/>
}
Get Media out of Vorto Media library (in this case a pdf)
IPublishedContent vorto = (IPublishedContent)Model.Content;
bool hasPDF = Model.Content.HasVortoValue("pdf");
var pdf = "";
if (hasPDF) {
var mediaItem = Convert.ToString(vorto.GetVortoValue<IPublishedContent>("pdf"));
int mediaID = Convert.ToInt16(mediaItem);
pdf = Umbraco.Media(mediaID).Url;
}
If (hasPDF)
{
<a href=“@pdf“>PDF DOWNLOAD</a>
}
Get content out of a checkbox (in this case it's a checkbox which sets a css value
This is a simple demonstration of how to make a simple subnavigation (dynamic)
Step 1: Go to your Umbraco and create a Document Type „SubNavigation“
Step 2: Add a (vorto)TextString „ListName“ (or call it how you want). ListName ist the name that is displayed in the subnavigation.
Step 3: Add this SubNavigation Document Type via Composition to every other tab.
Step 4: Go to each DocumentType and add the Current ID in a hyper reference tag. Like this:
Step 5: Go to your navigation partial (or wherever you render your navigation) and make a 2x foreach selection (there is already a good example fort hat in this document)
Step 6: Inside your 2x foreach loop you add this Code:
IPublishedContent currentPage = Umbraco.TypedContent(@item2.Id);
Umbraco help for everyone <3
Dear our.Umbraco.org Community I've been working with umbraco for several weeks now and I created a "cheat-sheet" with all the important stuff I've stumbled accros during developments. I'm a genuinely nice person - therefore I decided to share this file with you. Feel free to share, extend or improve my current Code. I'm still a beginner so don't expect too much. (Tested in Umbraco 7.6.5 and partially in 7.6.6)
Make a Redirect to Umbraco Login page on Startup for security reasons
(Copy This code into Master.cshtml)
Get Image out of normal Media library
Get Media out of Vorto Media library (in this case a pdf)
Get content out of a checkbox (in this case it's a checkbox which sets a css value
Basic Umbraco Navigation
1x selection foreach
2x selection foreach (show everything but pageComponents)
Get Content from certain Node
Multiple Media picker values + Subfolders (if someone uploads a folder filled with images into the media picker)
if (item.DocumentTypeAlias == "Folder") { foreach (var image in item.Children("Image")) { } } } }
Value of Related Links with Vorto
Umbraco Sub Navigation Concept
This is a simple demonstration of how to make a simple subnavigation (dynamic)
Step 1: Go to your Umbraco and create a Document Type „SubNavigation“ Step 2: Add a (vorto)TextString „ListName“ (or call it how you want). ListName ist the name that is displayed in the subnavigation. Step 3: Add this SubNavigation Document Type via Composition to every other tab. Step 4: Go to each DocumentType and add the Current ID in a hyper reference tag. Like this:
Step 5: Go to your navigation partial (or wherever you render your navigation) and make a 2x foreach selection (there is already a good example fort hat in this document) Step 6: Inside your 2x foreach loop you add this Code: IPublishedContent currentPage = Umbraco.TypedContent(@item2.Id);
Info: I used a 2x loop because i my structure is like this:
@item2 is the inner Selection oft he 2x foreach @page is the current Page you’re at. I used it for my main navigation.
That's it :)
Greetings - Tim
This is great Tim! So cool of you to share your tips & tricks!
I would propose a small change; use
Model.Content
instead ofCurrentPage
. See the Developers Reference -> Common PitfallsBut well done and keep sharing!
h5yr
/rune
is working on a reply...