Copied to clipboard

Flag this post as spam?

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


  • Pancheri Damien 16 posts 35 karma points
    Apr 26, 2013 @ 12:03
    Pancheri Damien
    0

    Umbraco V6 Rendering page problem

    Hi,

    I'm trying to display the content of a page in a parent template but I can't make it work.

    Here is my hierarchy:

    Homepage
      -- ContentPage

     

    For the templates it works like this:

    MasterPage
      -- HomePage
      -- SubPage
           -- ContentPage



    I would like to display the content of ContentPage in the SubPage template.

    Here is the code I implemented in the SubPage template:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using umbraco.MacroEngines @using umbraco.NodeFactory

    @{

    var model = Model; var backgroundImage = string.Empty;

    if(model.HasValue("backgroundImage")) { backgroundImage = string.Format(" style=\"background-image:url({0})\"", @Library.MediaById(Model.backgroundImage).umbracoFile); }

    var topNav = @umbraco.library.RenderMacroContent("", Model.Id); var mainNav = @umbraco.library.RenderMacroContent("", Model.Id);

    }


    This is giving me the content of the HomePage item.

    I already used this in a previous version of umbraco (4.7.2) and it worked. I guess the way to do it is different in V6 but I can't find out the solution.

    Any help is welcome.

     

    Thanks in advance,

    Dams

  • Pancheri Damien 16 posts 35 karma points
    Apr 26, 2013 @ 12:14
    Pancheri Damien
    0

    I know I should use CurrentPage but if I try something like this

    <pre>
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @inherits System.Web.WebPages.WebPage

    @{
    var currentpage = CurrentPage;
    }
    </pre>

    I absolutely need to inherits System.Web.WebPages.WebPage and CurrentPage is not recognized

  • Charles Afford 1163 posts 1709 karma points
    Apr 26, 2013 @ 13:23
    Charles Afford
    0

    Hi, Are you using Razor/MVC as apposed to webforms?

    Is ContentPage then a partial view and the SubPage a view?

    Thanks.  

    Charlie.

  • Pancheri Damien 16 posts 35 karma points
    Apr 26, 2013 @ 13:26
    Pancheri Damien
    0

    Hi Charlie,

    I'm using the Mvc rendering engine.

    ContentPage is not a partial view, it's a template and SubPage as well:
    MasterPage is the MasterPageFile of SubPage
    SubPage is the MasterPageFile of ContentPage 

    Thanks

  • Charles Afford 1163 posts 1709 karma points
    Apr 26, 2013 @ 13:36
    Charles Afford
    0

    Sorry this might sound stupid.  Why are you trying to use templates with MVC?.  Dont worry i see what you are refering to.

  • Charles Afford 1163 posts 1709 karma points
    Apr 26, 2013 @ 13:43
    Charles Afford
    0

    Sorry this might sound stupid.  Why are you trying to use templates with MVC?.  I think thats where you might be going wrong.  When you change the settings from WebForms to MVC.  With in the templates folder, those are now Views.

    Under the developer tab click on the PartialViewMacroFiles and create one called ContentPage.

    Put your ContentPage markup in here.

    In your SubPage (Template/View) call the ContentPage using @Html.RenderPartial("ContentPage");

    This should now render then content from the ContentPage. Hope this helps.

    Let me know :).

    Charlie

  • Pancheri Damien 16 posts 35 karma points
    Apr 26, 2013 @ 14:04
    Pancheri Damien
    0

    I understand your point of view and I agree ;-)

    The fact is that in the SubPage template, I have a piece of HTML that is the same for each content (ContentPage, SpecificContentPage, MoreSpecificContentPage ...)
    This html section contains the navigation menus, logo and the title and short description of each ContentPage.

    The idea is to retrieve the "@Model.title" and "@Model.ShortDesc" of the ContentPage and display them in the common section in the SubPage template and display the rest of the content (of ContentPage) below this commom section. (you still follow me?)

    I continued using the template because I come from a 4.7.2 umbraco version so it was natural for me.
    I'm not used yet to the partial views. Do you have a good link to learn about the partial views?

    Thanks.



    Juste made a test, I got this error:
    Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel>' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel>' could be found (are you missing a using directive or an assembly reference?)

    Source Error:

     
    Line 1:  @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    Line 2:     
    Line 3: @Html.RenderPartial("TopNavigationPV")

     

  • Charles Afford 1163 posts 1709 karma points
    Apr 26, 2013 @ 14:56
    Charles Afford
    0

    What have you got at the top of TopNavigationPV?

    Here we go, this will tell you all about it :D. http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx.  About half way down. Partial Views.  All they are doing is rendering html into the part of the page you put the partial.  Do you have visual studio?. Also if you i am gonna post on charlesafford.com this weekend about creating your first surface controller. (You need this for Umbraco MVC).  

  • Pancheri Damien 16 posts 35 karma points
    May 02, 2013 @ 12:21
    Pancheri Damien
    0

    Hi Charles,

    Sorry for late answers!
    Here is the content of my TopNavigationPV.cshtml

    <pre>

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>

     

    <ul class="topnav">

       <li>@Model.AncestorOrSelf(1).headerText</li>

    @foreach(var item in @Model.AncestorOrSelf(1).topNav)

    {

    <li><a href="@item.Url">@item.Name</a></li>

    }

     

    @{

     umbraco.MacroEngines.DynamicNode contentRoot = new umbraco.MacroEngines.DynamicNode(-1);

    }

    <li class="lang"><a href="#" class="currentLang">@Model.AncestorOrSelf(1).languageCaption</a>

            <ul>

            @foreach(var lang in contentRoot.ChildrenAsList)

            {

              if(lang.Id != Model.AncestorOrSelf(1).Id)

              {

                <li><a href="@lang.Url">@lang.Name</a></li>

              }

            }

            </ul>

      </li>         

    </ul>  

    </pre> 

    Unfortunately I don't have VS ... maybe it would be helpfull :P

    Thanks for your help! 

  • Charles Afford 1163 posts 1709 karma points
    May 02, 2013 @ 13:48
    Charles Afford
    0

    Ok, try replacing: 

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>

    WITH

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

Please Sign in or register to post replies

Write your reply to:

Draft