Copied to clipboard

Flag this post as spam?

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


  • Bilal Haidar 144 posts 410 karma points
    Feb 29, 2016 @ 21:46
    Bilal Haidar
    0

    Accessing properties with @CurrentPage.Site()

    Hi,

    In one of the starter kits, I've noticed the use of: @CurrentPage.Site().SiteLogo

    And in case, a property to be accessed in a recursive way, then: @CurrentPage.siteLogo

    Is accessing properties by Tab is a new thing to Umbraco? Which is better to use?

    Thanks

  • M T 35 posts 212 karma points
    Mar 01, 2016 @ 16:56
    M T
    0

    Hi Bilal,

    I use :-

    @CurrentPage._siteLogo

    It just works, I've never had any issue with it, even on a multi tenancy site. I couldn't tell you if its better than @CurrentPage.Site().SiteLogo, but it works and it's shorter, so it's a winner for me!

    Regards M

  • Bilal Haidar 144 posts 410 karma points
    Mar 01, 2016 @ 17:06
    Bilal Haidar
    0

    Thanks.

    So for example I can use a document type to store some configuration data and access them in templates?

    Thanks

  • M T 35 posts 212 karma points
    Mar 01, 2016 @ 17:19
    M T
    100

    Indeed you can, for example :-

     <!-- Meta tags -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    @if (CurrentPage.HasValue("pageDescription"))
    
    {
    <meta name="description" content="@CurrentPage.pageDescription">
    }
    else
    {
    <meta name="description" content="@CurrentPage._siteDescription">
    }
    
    @if (CurrentPage.HasValue("pageTitle"))
    
    {
    <title>@CurrentPage.pageTitle | @CurrentPage._siteTitle</title>
    }
    else
    {
    <title>@CurrentPage.Name | @CurrentPage._siteTitle</title>
    }
    
    <meta name="keywords" content="@CurrentPage.pageKeywords">
    
    
    @if (home.HasValue("siteLogo"))
    {
    <style>
        .logo {
            background-image: url('@CurrentPage._siteLogo') !important;
            background-size: contain !important;
        }
    </style>
    }
    

    All of these are set from Doc Type properties, via a tab I made called SEO.

    Note: The underscore takes you back to the root node. So you can access properties from there on your current page. There are lots of other ways of selecting levels though. Check this cheat sheet out, there isn't one for u7 but its a good reference :-

    https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    Regards M

Please Sign in or register to post replies

Write your reply to:

Draft