Skip to main content

Posts

Recent posts

Umbraco 8 Metadata Snippet, keywords, meta title.

Umbraco 8 Metadata Snippet, keywords, meta title, meta description: The following is a snippet that may help with generating metadata. I created this as a partial and added it to the Main Template.

If the metadata fields are not filled in on the backend by the editor, they are generated from the Page Name and the Name of the Website (applicationName).

----

In the example the backend meta fields are called:
"metaTitle"   (textstring)
"metaDescription"   (textstring)
"metaKeywords" (tags)

----

@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
    var applicationName = "My Website Name";
}
@if(Model.HasValue("metaTitle")){
    <title>@Model.Value("metaTitle")</title>

else
{
    if(Model.Id == Umbraco.ContentAtRoot().FirstOrDefault().Id)
    {
        <title>@applicationName</title>
    }
    else
    {
        <title>@Model.Name | @applicationName</title>
    }
}


@if(Model.HasValue("metaDescription"…

Umbraco 7 Get Image Crop from Media ID for specific image,simple version razor sniper

In Umbraco 7 to get a image crop from a image media item in the media folder, suppply the Media id number and the name of the image crop:

 <img src="@Umbraco.Media(1297).GetCropUrl("umbracoFile","imageCropName")" class="img-responsive">


Umbraco 7 Get Crops from Multi Media Picker for Image Gallery

Working in 7.9.2:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@if(CurrentPage.HasValue("galleryImages"))
                    {
                        <div class="row">

                            @{
                            char[] splitChar = { ',' };
                            string[] ids = CurrentPage.galleryImages.ToString().Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                            }
                            @foreach (var id in CurrentPage.galleryImages )
                            {
                        int imageId = int.Parse(id.ToString());
                            <div class="col-md-6">
                               <a href="@id.Url" data-fancybox="group" data-caption="@id.Name">
                                    <img src="@Umbraco.Media(@imageId).GetCropUrl("umbracoFile","square")" alt="" />
                     …

Umbraco 7 Get Media images by ID when using the Multi Media Picker to display a Gallery

Umbraco 7 Get Media images by ID when using the Multi Media Picker

This is usefull when creating a gallery of images.

1) In your Doctype add the Multiple Media Picker

2) Umbraco 7 Razor code snippet partial:


@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@helper RemoveExtensions(string stringIn)
{
 var thisTitle = stringIn;
                                        thisTitle = thisTitle.Replace(".jpg", "");
                                        thisTitle = thisTitle.Replace(".png", "");
                                        thisTitle = thisTitle.Replace(".jpeg", "");
                                        thisTitle = thisTitle.Replace(".gif", "");
                                        thisTitle = thisTitle.Replace(".bmp", "");
                                        thisTitle = thisTitle.Replace("-", " ");
                                        thisTitle = thisT…