Copied to clipboard

Flag this post as spam?

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


  • Zyliac 7 posts 50 karma points
    Feb 19, 2013 @ 14:34
    Zyliac
    0

    Access ContentPlaceHolder from the master of a master template.

    Hello All,

    I currently have the following structure in my templates folder.

    - Main Layout
    - Article Page
    - Guest Book

    I have a Main Layout, where all my static HTML is, and then a Article Page as a child of this Main Layout. I also have a guest book template, which should be identical to the Article Page, besides a ContentPlaceHolder in the buttom of the Main Layout. 

    Is there any way, i can define a ContentPlaceHolder in the Main Layout, and then use it directly in the Guest Book?

    Best regards.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 19, 2013 @ 20:03
    Jan Skovgaard
    0

    Hi Zyliac and welcome to our :)

    You should be able to define the placeholder in your Main layout template and then just call it on your Guest Book template.

    The brilliant thing about the placeholders is that if they're not being used (E.g. in your case the Article page) nothing is rendered.

    Hope this makes sense.

    /Jan

  • Zyliac 7 posts 50 karma points
    Feb 21, 2013 @ 12:14
    Zyliac
    0

    Thanks :).

    Yes, it makes a lot of sence. Its how i figured it would work aswell, so i have probably just done something wrong :p. 

    I have defined the placeholder as "<asp:ContentPlaceHolder id="GuestBook" runat="server"/>" in my Main Layout, and in the Guest Book i have:

    "<asp:Content ContentPlaceholderID="GuestBook" runat="server">
    <h1>Just some dummy text</h1>
    </asp:Content>"

    I just get an exception saying: "Cannot find ContentPlaceHolder 'GuestBook' in the master page '/masterpages/ArticlePageTemplate.master', verify content control's ContentPlaceHolderID attribute in the content page."

    I have made another "Guest Book" as a sibling to the Article Page, and this works(I just pasted all the content from the Article Page into the new Guest Book).

    Best regards.

     

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 22, 2013 @ 22:41
    Marc Goodson
    100

    Hi Zyliac

    In the masterpage in the middle you just need to add a content control that references the contentplaceholder in the main layout, that then that content control needs to contain another contentplaceholder to make the contentplaceholder available at the guest book level eg:

    Main Layout has

      <asp:ContentPlaceHolder id="GuestBook" runat="server"/>

    Article Page has

    <asp:Content ContentPlaceholderID="GuestBook" runat="server">
    <asp:ContentPlaceHolder id="GuestBook" runat="server"/>
    </asp:Content>"

    and  guest book has:

    <asp:Content ContentPlaceholderID="GuestBook" runat="server">

    <!-- Your Guest Book Content Here -->

    </asp:Content>

    Anything you put in the guest book content control will get 'passed up' the master page chain and appear in the correct place in the html in the Main Layout

    You can nest masterpages like this as deep as you like, it just gets confusing because of the names of the two controls are really similar, and you can put default content , inside a contentplaceholder high up the chain, ie site breadcrumb and then override it lower down by adding a blank content control with the relevant id 


  • Joao 53 posts 172 karma points
    Feb 26, 2013 @ 11:30
    Joao
    0

    Hello.

    I will use this thread since I have a similar problem. I'm trying to work with nested master pages but in a slighlty different way. My template structure is as follows:

    ->Home

       -> MainContent

            ->ContentBlock

    Home layout has:

    <asp:ContentPlaceHolder Id="MainContentPlaceHolder" runat="server" />

    MainContent Layout has

    <asp:Content ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <asp:ContentPlaceHolder Id="ContentBlockPlaceHolder" runat="server" />

    </asp:Content>

    ContentBlock Layout has:

    <asp:Content ContentPlaceHolderID="ContentBlockPlaceHolder" runat="server">

     <!-- My code -->

    </asp:Content> 

    Whenever I run the page, the contents inside the ContentBlock are not displayed. I have no idea why because I seem to be doing things right. I am very new to master pages so I'm probably missing something here. I also tried adding content one more time to see if that was the problem but it still does not work.

    Any help would be appreciatted.

     

    Cheers 

     

     

  • Zyliac 7 posts 50 karma points
    Feb 26, 2013 @ 12:48
    Zyliac
    0

    Thanks a lot Marc. I actually thought i tried this, but i must have done something wrong, because it works now! :p. 

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 26, 2013 @ 12:50
    Marc Goodson
    0

    Hi Joao

    That's strange, I just cut and pasted your Content and ContentPlacholder tags as you have above into some nested masterpage, and it all seems to work ok!!

    Check the 'page template' the page you are testing it on is using, make sure it is using your 'ContentBlock' page template, because if it is using a different one, that may account for the missing contents!

    Otherwise try putting comments just before and just after the content place holders, then view the page, the comments that are missing may point to the place where it is not wired correctly.

    eg

    <asp:Content ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <!--ContentBlockPlaceHolder Starts Here -->

    <asp:ContentPlaceHolder Id="ContentBlockPlaceHolder" runat="server" />

    <!--ContentBlockPlaceHolder Ends Here -->

    </asp:Content>

    The other common confusion is if you have content inside a 'contentplaceholder', and a content control in the masterpage below referencing it, that will override the default content in the content place holder, BUT that doesn't appear to be what is happening here.

    eg

    <asp:ContentPlaceHolder Id="ContentBlockPlaceHolder" runat="server" >

    <h1>Default Content</h1>

    <p>This default content will show, unless the template below references this contentplaceholder</p>

    </asp:ContentPlaceHolder>

     

     

  • Zyliac 7 posts 50 karma points
    Feb 26, 2013 @ 12:55
    Zyliac
    0

    Joao; I just tried something semilar to what you wrote, and it works for me. Have you tried just writing out some text where you have your  <!-- My code --> ?. The problem might not be the placeholderĀ“, but the stuff you are trying to insert. 

  • Joao 53 posts 172 karma points
    Feb 26, 2013 @ 13:21
    Joao
    0

    I have tried putting comments wraping the ContentBlock with comments inside the MainContent template:

    <!-- block goes here -->
    <asp:ContentPlaceHolder Id="ContentBlockPlaceHolder" runat="server" />
    <!-- end of block -->

    Inside the ContentBlock template i have stuff inside:

    <asp:Content ContentPlaceHolderID="ContentBlockPlaceHolder" runat="server">

    <!-- this inside the block template -->

    <div><umbraco:Item field="blockText" runat="server" /></div>

    <div><umbraco:Item field="blockQuote" runat="server" /></div>

    <p>THIS SHOULD WORK!</p>

    <!-- this is inside the block template end -->

    </asp:Content>

    What I get in the source is:

    <div class="text_descrip">
    This page is dedicated to the Pig.
    </div>
    <!-- block goes here -->

    <!-- end of block -->

    As you can see it's empty. This must be a really stupid error and I can't seem to find it :(

    I tried to view the ContentBlock by it self (going through the direct link in the content panel) and it does show what I have inserted. It does however replace some of the things inside the MainContent template.

    Inside the MainContent I have:

    <asp:Content ContentPlaceHolderID="MainContentPlaceHolder" runat="server">


    <umbraco:Macro Alias="2ndLevelNavigation" runat="server" />


    <div class="text_descrip">
    <umbraco:Item field="textDescription" runat="server" />
    </div>


    <!-- block goes here -->
    <asp:ContentPlaceHolder Id="ContentBlockPlaceHolder" runat="server" />
    <!-- end of block -->

    </asp:Content> 

    What I get in the source is this:

    <ul><li><a href="/species/pig.aspx">Pig</a></li><li><a href="/species/cow.aspx">Cow</a></li></ul>
    <div class="text_descrip">

    </div>
    <!-- block goes here -->


    <!-- this inside the block template -->

    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>

    <div>Some people see things as they are and ask why, I dream things that never were and say why not"</div>

    <p>THIS SHOULD WORK!</p>

    <!-- this is inside the block template end -->


    <!-- end of block -->

    The Description goes empty but the Navigation stays :/ 

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 26, 2013 @ 17:02
    Marc Goodson
    0

    Right, I kind of think I may understand why it is not working on how you think it should, but I'm not sure I'll be able to explain it well, and may be wrong but this is what I'm thinking/guessing

    Basically when you go to your ContentBlock directly, in the front end, Umbraco is displaying the content of the node with the 'Content Block' Page Template, this template inherits the MainContentPlaceHolder, ie the navigation macro, and this runs ok, then the next bit is to write out the contents of the textDescription field, my guess is the ContentBlock node doesn't have a textDescription field ? and so is why this in the context of the 'contentBlock' this bit is blank, then the content of the content blak the 'inside the block template bit' is written out inside the ContentBlockPlaceHolder via the 'blockText' and 'blockQuote; properties, and so appears!

    When you visit directly to the page with the 'This page is dedicated to the Pig' description in, that doctype does have a property called textDescription and so the description is displayed, but I'm guessing this docType doesn't have a 'blockText' or 'blockQuote' property or is using a different page template and so doesn't get the <content section for the ContentBlockPlaceHolder and so nothign displays in there. Basically there is nothing to tell umbraco that when you display a page, you want that particular contentblock to appear on it.

    If I'm right then you either need to just need one docType that has all the properties in that you need to write out, or your master doctype needs some kind of 'picker' control to pick the relevant 'content block' and you would write a razor macro to write this out, or if the contentblock is a child node of the main page node, you could write a razor macro to write out any children of contentblock type within the contentblock content section...

    I may not have made sense there, and apologies if I've added to the confusion :-)

  • Joao 53 posts 172 karma points
    Feb 27, 2013 @ 10:03
    Joao
    0

    What you are saying does make sense. The ContentBlock doc type is a child of the MainContent doc type,(thus is has the textDescription field, but it is empty so nothing appears.

    Having a doctype with all the info is not an option, I would like for the editor of content to write as many ContentBlocks as he wants and they would all be displayed. The ContentBlock is a child node of the MainContent node, does this mean my best course of action os to write a macro that displays the children of the MainContent and I place this macro inside the content block section of Maincontent? 

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 27, 2013 @ 10:23
    Marc Goodson
    0

    Yes, the best course of action is to write a macro to loop through and write out all the child 'ContentBlocks' nodes of the current page, and put this macro in the ContentBlock Content section.

    The Razor DynamicNode Cheat sheet, is a godsent for working out how thse things work: http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet and also the Razor Feature Walkthrough: http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets

    but the razor will be something like this:

    @foreach(dynamic contentBlockItem in Model.ContentBlocks.Where("Visible")){

    <div class="contentBlockHolder">

    <h2>@contentBlockItem.Name</h2>

    @contentBlockItem.blockText

    <blockquote>

    @contentBlockItem.blockQuote

    </blockquote>

     

    </div>

    }

    that's might have syntax errors, but should hopefully give you an idea of where to start.

    good luck

     

    marc

  • Joao 53 posts 172 karma points
    Feb 27, 2013 @ 10:24
    Joao
    0

    Thank you. I will get to work. I will let you guys know how it went. 

    Cheers 

  • Joao 53 posts 172 karma points
    Feb 27, 2013 @ 14:42
    Joao
    0

    I have been unsuccessful in solving my problem so I started this new thread where I explain everything as best as I can with some images of the content, template and doc type structures, as well as my atempt on the macro. 

Please Sign in or register to post replies

Write your reply to:

Draft