Copied to clipboard

Flag this post as spam?

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


  • David Johnson 12 posts 32 karma points
    Oct 21, 2011 @ 17:07
    David Johnson
    0

    Little issue with @Model.Ancestor (razor)

    Hi there

    I'm very new to umbraco so excuse my poor description. I hope this makes sense. I'm building a site where the navigation bar takes you to 3 different parts of the company (all branded differently).

    Pages are set up like this:

    • Group Home
    • Company 1
      - Page 1
      - Page 2
      - etc
    • Company 2
      - Page 1
      - Page 2
      - etc
    • Company 3
      - Page 1
      - Page 2
      - etc

    Company 1 (and sub pages) have the Company 1 logo at the top of the page.
    Company 2 (and sub pages) have the Company 2 logo at the top of the page.
    Company 3 (and sub pages) have the Company 3 logo at the top of the page.

    In each case this logo is a link which should lead you back to that specific company homepage.

    In my master page I have included the following macro:

    <umbraco:Macro Alias="logo" logo_id="[$logo]" runat="server" />

    My razor scripting file has the following code:

    @{
    string logo_id = Parameter.logo_id;
    <a href="@Model.Ancestor">
    <img src="@Model.MediaById(logo_id).umbracoFile" alt="logo"/>
    </a>
    }

    The Problem

    If I'm on Group Home, Company 1, Company 2 or Company 3 then the logo link takes me to the right page (essentially just refreshing the page).

    But when I'm on any of the Company sub pages the logo link doesn't take me back to the Company main page. It just loads the same page.

    I've gotten as far as I have with a fair bit of help already. My knowledge is limited but I was expecting @Model.Ancestor to basically go back up the tree to the top most level. Meaning that whichever part of the site I was in, I could easily access the company home page by clicking the logo.

    Can anyone give me any pointers or suggestions as to what I should look into to solve this problem?

  • David Johnson 12 posts 32 karma points
    Oct 21, 2011 @ 18:22
    David Johnson
    0

    Wehey! I solved it (don't know how but it works)

    @{

    string logo_id = Parameter.logo_id;

    <a href="@Model.AncestorOrSelf(2).Url" title="Link to home">
    <img src="@Model.MediaById(logo_id).umbracoFile" alt="active logo"/>
    </a>

    }
Please Sign in or register to post replies

Write your reply to:

Draft