Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick 95 posts 492 karma points
    Mar 16, 2017 @ 17:34
    Nick
    1

    Global settings node

    Hi,

    Using Umbraco version 7.5.4, I've created a separate Global settings node outside of the main structure see image below, which just contains global info for the site. When I add the corresponding Umbraco field within my page templates the info doesn't render, any clue where I am going wrong. As always much appreciated in with any help. enter image description here

    Kind regards

    Nick

  • Kevin Jump 2341 posts 14868 karma points MVP 8x c-trib
    Mar 16, 2017 @ 18:41
    Kevin Jump
    105

    Hi,

    i would guess it because you are not finding the global settings node before you ask for the values.

    in your template you will first need to find the global settings node ?

    something like :

    var settings = Umbraco.TypedContentSingleAtXPath("\\globalSettings");
    var twitterUrl = settings.GetPropertyValue<string>("twitterUrl")
    

    might work . assuming your global site settings node doctype is called globalSettings

    i usually put something this in a helper class, then you can call it without doing the lookup.*

    e.g.

    public static class GlobalSettingsExtensions
    {
        public static IPublishedContent GlobalSettings(this UmbracoHelper umbraco)
        {
            return umbraco.TypedContentSingleAtXPath("\\globalSettings");
        }
    }
    

    would (when namespace is included in the razor) let you do something like:

    @Umbraco.GlobalSettings.GetPropertyValue("twitterUrl")
    

    * error checking not included

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 17, 2017 @ 13:01
    Michaël Vanbrabandt
    0

    Hi Kevin,

    nice tip about using an extension on the UmbracoHelper class for returning a root node!

    Thanks!

    /Michaël

  • Micha Somers 134 posts 597 karma points
    Jul 12, 2017 @ 19:51
    Micha Somers
    0

    Kevin,

    Thanks for this helper class.

    Needed to change a few things, but then it worked great...

    BTW ... the changes I made:

    • changed backward slashes to forward slashes => ("//globalSettings");

    • added round brackets to GlobalSettings => @Umbraco.GlobalSettings().GetPropertyValue("twitterUrl")

  • Nick 95 posts 492 karma points
    Mar 17, 2017 @ 12:56
    Nick
    0

    Thanks for your help, your solution worked great.

    Cheers

    Nick

  • Graham Davis 110 posts 376 karma points
    Aug 14, 2017 @ 17:00
    Graham Davis
    0

    Thanks for posting this. I need to the same thing!

Please Sign in or register to post replies

Write your reply to:

Draft