Copied to clipboard

Flag this post as spam?

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


  • Christine 115 posts 288 karma points
    Apr 10, 2014 @ 21:25
    Christine
    0

    Referencing master pages from second level

    Hello,

    I would like to know how I can reference a master page from a template when it is not at the top level.

    For example, the following urls use the same template. 

    www.myurl.com/mypage

    www.myurl.com/foldername/myotherpage

    The second one, "myotherpage" cannot find the master page while "mypage" can.

    I tried to add a "~", but that didn't work

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{

        Layout = "~/Layout.cshtml";

    }

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 10, 2014 @ 21:37
    Jan Skovgaard
    0

    Hi Christine

    I imagine that your templates are structured like this in the Umbraco backoffice

    Layout.cshtml - Template1.cshtml - Template2.cshtml - Etc.

    Then it should be enough to write the reference like

    @{
        Layout = "Layout.cshtml";
    }
    

    Simply remove the ~ character - does that help?

    /Jan

  • Christine 115 posts 288 karma points
    Apr 10, 2014 @ 21:42
    Christine
    0

    Yes the templates are arranged like this but neither

    @{
       
    Layout="Layout.cshtml";
    }

    or

    @{
       
    Layout="~/Layout.cshtml";
    }

    will pick up the master page when a page that is not at the top level

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 10, 2014 @ 21:43
    Jan Skovgaard
    0

    Hi Christine

    Do you mind sending a screenshot of your master template and your textpage templates, or what you have named them? :)

    I need to be certain of your context before I can advise further.

    Cheers, Jan

  • Christine 115 posts 288 karma points
    Apr 10, 2014 @ 21:52
    Christine
    0

    Sure!  I have taken a screen shot of my Content Pages & Masterpage/Templates

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 10, 2014 @ 21:58
    Jan Skovgaard
    0

    Ok, and which of the above templates is causing the issue?

    And what does the error message say?

    /Jan

  • Christine 115 posts 288 karma points
    Apr 10, 2014 @ 22:07
    Christine
    0

    In the pages inside the folder "lp" i'm using the Sidebar template.

    If i do

    @{
       
    Layout="Layout.cshtml";
    }

    There is no error, the page renders with no styles.  If I simply preview the page from the back office, it's fine

     

    If I do

    @{
       
    Layout="~/Layout.cshtml";
    }

    I get a not found message:

    Server Error in '/' Application.


    The layout page "~/Layout.cshtml" could not be found at the following path: "~/Layout.cshtml".

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.Web.HttpException: The layout page "~/Layout.cshtml" could not be found at the following path: "~/Layout.cshtml".

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 10, 2014 @ 22:15
    Jan Skovgaard
    100

    Hi Christine

    Ok, so the approach of using "Layout.cshtml" is probably right. So change it to that.

    Now let me see the code of your Layout.cshtml template - I suspect the missing styles are due to the styles being referenced in a relative manner instead of an absolute path.

    /Jan

  • Christine 115 posts 288 karma points
    Apr 10, 2014 @ 22:20
    Christine
    0

    ohhhh ok, you are very right - i need to put that tilda on the style sheet.  I did this and it works now - thanks very much!

    <head>

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta name="robots" content="index,follow" />

    <meta name="description" content="@Umbraco.Field("metaDescription")" />

    <meta name="keywords" content="@Umbraco.Field("metaKeywords")" />

    <title>@Umbraco.Field("pageTitle")</title>

    <link rel="shortcut icon" type="image/x-icon" href="~/favicon.ico"/>

    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>

    <link href="~/css/Main.css" rel="stylesheet">

    </head>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 10, 2014 @ 22:26
    Jan Skovgaard
    0

    Hi Christine

    Happy to hear you managed to get it solved :-)

    Happy umbracoing.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft