Copied to clipboard

Flag this post as spam?

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


  • Roger Newmon 4 posts 84 karma points
    Jan 29, 2020 @ 04:16
    Roger Newmon
    0

    Umbraco 8 Root Site Logo URL issues....

    Umbraco 8... What am I doing wrong?!?!?! The IF line works now but the lines that follow fail... I can not figure out what is happening. Everything I read says

    @Model.Content.Value("pageTitle")
    @Model.Content.Value<string>("pageTitle")
    

    How do I do that from Root?

    var home = Model.Content.Root(); var homePg = (HomePage)Model.Content.Root();

    Neither work the only one that compiled with the IF statement was

    string.IsNullOrEmpty(homePg.Value<IPublishedContent>("siteLogo").Url)
    

    This FAILS:

    string.IsNullOrEmpty(homePg.Value("siteLogo").Url) 
    

    WHY???? I still can not fix the line:

    Error:

    Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'

    Source Error:

    Line 41: {
    Line 42:     <div class="nav-link--home">
    Line 43:         <img class="logo-image" src="@homePg.Value<IPublishedContent>("siteLogo").Url()"  >
    Line 44:     </div>
    Line 45: }
    

    Partial Macro View:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Web
    
    @{  
        var home = Model.Content.Root(); 
        var homePg = (HomePage)Model.Content.Root();
        var homepageSelected = @Model.Content.Id == home.Id ? " class=\"nav-link active\"" : " class=\"nav-link\"";
    }
    
    @if (homePg.Value<IPublishedContent>("siteLogo")  != null && !string.IsNullOrEmpty(homePg.Value<IPublishedContent>("siteLogo").Url))
    {
        <div class="nav-link--home">
            <img class="logo-image" src="@homePg.Value<IPublishedContent>("siteLogo").Url"  >
        </div>
    }
    
  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Jan 29, 2020 @ 08:37
    Matt Barlow | jacker.io
    0

    In Umbraco 8 .Content has been removed.

    So your code should be:

    @{ 
    var homePg = Model.Root();
    var homepageSelected = Model.Id == homePg.Id;
    var homeNav = homepageSelected ? class=\"nav-link active\"" : " class=\"nav-link\"";
    }
    

    then

    @if(homepageSelected){
     // do something if on the homepage
    }
    

    and to output the CSS class would be:

    <img src="#" @homeNav />
    
  • Roger Newmon 4 posts 84 karma points
    Jan 29, 2020 @ 13:05
    Roger Newmon
    0

    No there is more code in the file that is just the section that errors. The homepageSelected is used in a different context.

    I just realized it did not post correctly.

    Here is the issue: The below line fails:

     <img class="logo-image" src="@homePg.Value<IPublishedContent>("siteLogo").Url"  >
    

    Error: Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'

    This works however:

       @if (homePg.Value("siteLogo")  != null && !string.IsNullOrEmpty(homePg.Value<IPublishedContent>("siteLogo").Url))
    

    I don't understand why the IF statement can use:

    homePg.Value<IPublishedContent>("siteLogo").Url
    

    And not error out but the IMG tag can not. I tryed many options for the IF statement until I finally got that working so I thought I had the solution but that solution did not fix the IMG tag. It makes no sense to me!

  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Jan 29, 2020 @ 13:17
    Matt Barlow | jacker.io
    0

    The siteLogo property could be of type (if allow multiple is selected)<IEnumerable<IPublishedContent>>, this is a group / list of IPublishedContent, so you need to return the first one, see below:

     var logoUrl = homePg.Value<IEnumerable<IPublishedContent>>("siteLogo").FirstOrDefault()?.Url;
    
  • Roger Newmon 4 posts 84 karma points
    Jan 29, 2020 @ 13:23
    Roger Newmon
    0

    The Line still errors with the SAME error:

    Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'

    Line 41: {
    Line 42:     <div class="nav-link--home">
    Line 43:         <img class="logo-image" src="@homePg.Value<IEnumerable<IPublishedContent>>("siteLogo").FirstOrDefault()?.Url"  >
    Line 44:     </div>
    Line 45: }
    

    Also what is the equivalent of:

    @Model.Value("title")
    

    To:

    Model.Content.Root(); 
    
  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Jan 29, 2020 @ 14:04
    Matt Barlow | jacker.io
    100

    Ok, the issue is you are using a PartialViewPageMacro... which works differently to UmbracoViewPage.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Web
    @using Umbraco.Web.PublishedModels
    @using Umbraco.Core.Models.PublishedContent
    
    @{
        var home = Model.Content.Root();
        var homePg = (HomePage)Model.Content.Root();
        var homepageSelected = @Model.Content.Id == home.Id ? " class=\"nav-link active\"" : " class=\"nav-link\"";
    }
    
    @if (homePg.Value<IPublishedContent>("siteLogo") != null && !string.IsNullOrEmpty(homePg.Value<IPublishedContent>("siteLogo").Url))
    {
        <div class="nav-link--home">
            <img class="logo-image" src="@(homePg.Value<IPublishedContent>("siteLogo").Url)">
        </div>
    }
    

    The problem is you needed brackets around your code when you retrieve the logo url, as the razor rendering engine was assuming the first " was the close of the src.

  • Roger Newmon 4 posts 84 karma points
    Jan 29, 2020 @ 14:24
    Roger Newmon
    0

    That finally worked. Umbraco 8 is killing me I don't understand why everything is accessed different.

    I think I would save years of many developers life if someone could document just one simple page:

    How to access the Root OR the actual CurrentPage Model properties... i.e.

    Model.Value<double>("amount")
    Model.Value<IHtmlString>("bodyContent")
    Model.Value("bodyContent")
    Model.Content.Value<IPublishedContent>("image")
    Model.Value<IEnumerable<IPublishedContent>>("sliders")
    

    FROM each of these:

    Umbraco.Web.Macros.PartialViewMacroPage
    umbraco.MacroEngines.DynamicNodeContext
    System.Web.Mvc.WebViewPage
    Umbraco.Web.Mvc.UmbracoTemplatePage
    Umbraco.Web.Mvc.UmbracoViewPage
    Umbraco.Web.Mvc.UmbracoViewPage<Model>
    UmbracoViewPage<dynamic>
    

    Because they are Not the same and I can't figure out how to take a code snippet from one page type and use it in a different page type... I don't know why there is not some helper conversion for this?!?!?!?! Accessing them should be some how consistent from each type in my opinion.

    If I had a mapping equivalent, for Umbraco 8 it would prevent MANY grey hairs!!! It would need to include examples of both Root as well as CurrentPage Models.

    Whoever could document that would be pure genius!

  • Bradford Ewing 2 posts 72 karma points
    Oct 28, 2020 @ 15:35
    Bradford Ewing
    0

    Roger Newmon,

    Thanks very much! Your digging into this really helped me with my issue:

    BEFORE (threw errors):

    @(Model.Value("SiteLogo").Url)

    AFTER (works perfectly):

    @(Model.Value<IPublishedContent>("SiteLogo").Url)

    Thank you again! After inserting <IPublishedContent> after "Model.Value", everything worked for me.

Please Sign in or register to post replies

Write your reply to:

Draft