Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    May 23, 2013 @ 18:21
    Steve
    0

    Content Placeholders

    I have a couple of templates based off a master. I am trying to add content using  'ContentPlaceHolder'. See the last couple of lines:

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

    I have refrenced this in a nested template like this, but I am getting an error previewing the page.

    <%@ Master Language="C#" MasterPageFile="~/masterpages/NewsInternalPage.master" AutoEventWireup="true" %>
    
    <asp:content ContentPlaceHolderId="headContent" runat="server">
        <link rel="stylesheet" type="text/css" href="/css/smallSlider.css">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="/scripts/bxslider.js"></script>
        <script>
            $(document).ready(function(){
                  $('.bxslider').bxSlider({
                      slideMargin:0,
                      auto: true,
                      pause: 6000,
                      slideWidth: 180,
                      minSlides: 1,
                      maxSlides: 3,
                      pager: false,
                      controls: true,
                      speed:1000,
                      pager:false,
                      pagerType:'full'
                  });
            });
        </script>
      <!--
      <sc ript type="text/javascript" src="/scripts/news-category.js"></sc ript>
      -->
    
      <asp:ContentPlaceHolder Id="headContent" runat="server">
      </asp:ContentPlaceHolder>
    </asp:content>
    
    <asp:content ContentPlaceHolderId="bodyContent" runat="server">
        <div id="category-content">
        <umbraco:Item field="categoryContent" runat="server" />
        </div>
      <umbraco:Macro Alias="NewsCategory" runat="server"></umbraco:Macro>
        <asp:content ContentPlaceHolderId="ankle" runat="server">
            <div class="sliderData">
                <umbraco:Item field="smallSlider" runat="server" />
            </div>
        </asp:content>
    
    </asp:content>
        
    <%@ Master Language="C#" MasterPageFile="~/masterpages/BasePage.master" AutoEventWireup="true" %>
    
    <asp:content ContentPlaceHolderId="headContent" runat="server">
      <link rel="stylesheet" href="/css/footer.css" type="text/css" />
    
      <asp:ContentPlaceHolder Id="headContent" runat="server">
      </asp:ContentPlaceHolder>
    </asp:content>
    
    <asp:content ContentPlaceHolderId="bodyContent" runat="server">
      <div id="heightDiv">
        <asp:ContentPlaceHolder Id="bodyContent" runat="server">
        </asp:ContentPlaceHolder>
    
      </div>
      <asp:ContentPlaceHolder Id="ankle" runat="server">
        </asp:ContentPlaceHolder>
    </asp:content>
  • Steve 472 posts 1216 karma points
    May 23, 2013 @ 21:51
    Steve
    0

    This can't be this difficult. Shouldn't I be able to create this:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/NewsCategory.master" AutoEventWireup="true" %>
    
    <asp:content ContentPlaceHolderId="headContent" runat="server">
    
    </asp:content>
    
    <asp:content ContentPlaceHolderId="ankle" runat="server">
        <asp:content ContentPlaceHolderId="ankle" runat="server">
            <div class="slider-wrapper">
                <umbraco:Item field="smallSlider" runat="server" recursive="true" />
                <p class="slider-title">By the Numbers</p>
            </div>
        </asp:content>
    </asp:content>

    As a child of the template of this:

    
    
    
    
    <%@ Master Language="C#" MasterPageFile="~/masterpages/NewsInternalPage.master" AutoEventWireup="true" %>
    
    <asp:content ContentPlaceHolderId="headContent" runat="server">
        <link rel="stylesheet" type="text/css" href="/css/smallSlider.css">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="/scripts/bxslider.js"></script>
        <script>
            $(document).ready(function(){
                  $('.bxslider').bxSlider({
                      slideMargin:0,
                      auto: true,
                      pause: 6000,
                      slideWidth: 180,
                      minSlides: 1,
                      maxSlides: 3,
                      pager: false,
                      controls: true,
                      speed:1000,
                      pager:false,
                      pagerType:'full'
                  });
            });
        </script>
      <!--
      <sc ript type="text/javascript" src="/scripts/news-category.js"></sc ript>
      -->
    
      <asp:ContentPlaceHolder Id="headContent" runat="server">
      </asp:ContentPlaceHolder>
    </asp:content>
    
    <asp:content ContentPlaceHolderId="bodyContent" runat="server">
        <div id="category-content">
        <umbraco:Item field="categoryContent" runat="server" />
        </div>
      <umbraco:Macro Alias="NewsCategory" runat="server"></umbraco:Macro>
        <asp:ContentPlaceHolder Id="ankle" runat="server"></asp:ContentPlaceHolder>
    
    </asp:content>
      I don't get it! Why is this not working?
  • lothar 25 posts 99 karma points
    May 24, 2013 @ 14:33
    lothar
    0

    As i've looked into your template I came across this:

    <asp:content ContentPlaceHolderId="bodyContent" runat="server">
        <div id="category-content">
            <umbraco:Item field="categoryContent" runat="server" />
        </div>
        
        <umbraco:Macro Alias="NewsCategory" runat="server"></umbraco:Macro>
        
        <asp:content ContentPlaceHolderId="ankle" runat="server">
            <div class="sliderData">
                <umbraco:Item field="smallSlider" runat="server" />
            </div>
        </asp:content>
    </asp:content>

    You cannot nest content controls, you define your content controls at the same level.
    It should look like this:

    <asp:content ContentPlaceHolderId="bodyContent" runat="server">
        <div id="category-content">
            <umbraco:Item field="categoryContent" runat="server" />
        </div>
        
        <umbraco:Macro Alias="NewsCategory" runat="server"></umbraco:Macro>
    </asp:content>

    <asp:content ContentPlaceHolderId="ankle" runat="server">
        <div class="sliderData">
            <umbraco:Item field="smallSlider" runat="server" />
        </div>
    </asp:content>

    The content from each Content control will then be injected into the given ContentPlaceHolder.


    Also, you defined your content control twice here with the same id.
    You only need to define 1 ankle content control

    <asp:content ContentPlaceHolderId="ankle" runat="server">
            <asp:content ContentPlaceHolderId="ankle" runat="server">
                    <div class="slider-wrapper">
                            <umbraco:Item field="smallSlider" runat="server" recursive="true" />
                            <p class="slider-title">By the Numbers</p>
                    </div>
            </asp:content>
    </asp:content>


    With these changes your templates should be working.

  • Steve 472 posts 1216 karma points
    May 28, 2013 @ 16:21
    Steve
    0

    Thanks,

    That put the content in the place holder, but I am still confused as to how to get the proper location for my conent within the page?

  • Steve 472 posts 1216 karma points
    May 28, 2013 @ 19:17
    Steve
    0

    I have several nested templates, but it seems that I can't apply the controlls to any of the higher templates only the parent of the template that has the <asp:content>

    Is that correct?

  • Steve 472 posts 1216 karma points
    May 28, 2013 @ 21:06
    Steve
    0

    Here are a couple of screen grabs to show you what my template structure is like. I am just trying to add the <asp:content ContentPlaceHolderId = "ankle" runat="server"> to the child template of "News Category". I keep getting an error using the method in the screen captures. Any help would be appreciated. Thanks!

  • lothar 25 posts 99 karma points
    May 29, 2013 @ 19:16
    lothar
    1

    As you said, the page allows only Content controls with the parent's ContentPlaceHolders and not the ancestors ContentPlaceHolders
    What you need to do is write it like this:


    Master Page

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <asp:ContentPlaceHolder ID="ankle" runat="server">
    </asp:ContentPlaceHolder>
    </asp:Content>

    Nested Master Page

    <asp:Content ContentPlaceHolderID="ankle" runat="server">
        <asp:ContentPlaceHolder ID="ankle" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Content>

    Nested Nested Master's Page

    <asp:Content runat="server" ContentPlaceHolderID="ankle">
    </asp:Content>

     

    I do suggest to use diffrent ID's to have a better view on what you write:

    Master Page

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <asp:ContentPlaceHolder ID="ankle1" runat="server">
    </asp:ContentPlaceHolder>
    </asp:Content>

    Nested Master Page

    <asp:Content ContentPlaceHolderID="ankle1" runat="server">
        <asp:ContentPlaceHolder ID="ankle2" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Content>

    Nested Nested Master's Page

    <asp:Content runat="server" ContentPlaceHolderID="ankle2">
    </asp:Content>
  • Steve 472 posts 1216 karma points
    May 29, 2013 @ 20:04
    Steve
    0

    I had to go all the way back up the ancestors, inserting content placeholders, to the "NewsLeftNav" template, that showed the correct location to insert the conten.

    I don't understand why it wouldn't show up on those templates that are inbetween "NewsLeftNav" and the actual template where the asp:content was located (NewsCategory) though? Very confused.

    Also, I thought the ID's needed to be the same?

  • lothar 25 posts 99 karma points
    May 29, 2013 @ 20:09
    lothar
    0

    You didn't get any errors because you didn't define the asp:Content there.

    ContentPlaceHolders are optional so some pages implement all content placeholders of parent, some don't.

    -----

    They don't need to have the same ID to use them.

  • Steve 472 posts 1216 karma points
    May 29, 2013 @ 20:13
    Steve
    0

    If they are optional, then why couldn't I have just placed one ContentPlaceHolder at the template I needed the content injected and then put the content on the nested template I was rendering? Since each template was nested anyway.

  • lothar 25 posts 99 karma points
    May 29, 2013 @ 20:18
    lothar
    0

    That's true, you only needed to define it where your nested pages use it.

    I assumed that the other templates also needed to use the ankle ContentPlaceHolder so that's why I suggested to nest it all the way up.

  • Steve 472 posts 1216 karma points
    May 29, 2013 @ 20:21
    Steve
    0

    When I take the ContentPlaceHolder out of any of the templates that I don't wan't it on it stops rendering the page.

    http://www.rose-hulman.edu/news/rose-hulman-commencement-2013.aspx

  • Steve 472 posts 1216 karma points
    May 29, 2013 @ 20:38
    Steve
    0

    I only needed it At "News Category", but the location for placement is not accessable except at the ancestor "News Left Nav". So I placed the ContentPlaceHolder there and "News Internal Page", because if I removed the ContentPlaceHolder from the "News Internal Page" it will not render the "News Category" page. Here is the page with the working "ankle" content at the bottom of the page. http://www.rose-hulman.edu/news/rose-hulman-commencement-2013.aspx

     

  • lothar 25 posts 99 karma points
    May 29, 2013 @ 20:44
    lothar
    100

    I have confused you.

    What I ment about placing it where you needed it, was that you only need to define it where you need it like this:


    Root Master Page

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
        <asp:ContentPlaceHolder ID="body" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Content>

    Nested Master Page

    <asp:Content ContentPlaceHolderID="body" runat="server">
        <asp:ContentPlaceHolder ID="topbody" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Content>

    Nested Nested Master Page

    <asp:Content ContentPlaceHolderID="topbody" runat="server">
        <asp:ContentPlaceHolder ID="ankle" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Content>

    Content Page

    <asp:Content runat="server" ContentPlaceHolderID="ankle">
    </asp:Content>


    As you can see, naming your controls diffrently is important to the meaning :)

    And as I have written this, I see the screenshot and that's what you did.
    But you needed the content at the place in NewsLeftNav and since the content is several levels below you still need to nest ContentPlaceHolders to let it reach your last page where your content is.

    Sorry for the confusion.

  • lothar 25 posts 99 karma points
    May 29, 2013 @ 21:06
    lothar
    0

    What I ment by optional I will explain this by an example


    Root Master Page

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
        <asp:ContentPlaceHolder ID="body" runat="server">
        </asp:ContentPlaceHolder>
        <asp:ContentPlaceHolder ID="footer" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Content>


    Nested Page

    <asp:Content ContentPlaceHolderID="body" runat="server">
        BODY HERE
    </asp:Content>

    <asp:Content ContentPlaceHolderID="footer" runat="server">
        FOOTER HERE
    </asp:Content>

    Nested Page 2

    <asp:Content ContentPlaceHolderID="body" runat="server">
        BODY HERE
    </asp:Content>


    As you can see, the root master page has 2 nested pages on the same level, but only 1 defines both placeholders and the other only the body

    This will result in

    Page 1:

    BODY HERE
    FOOTER HERE

    Page 2:

    BODY HERE
  • Steve 472 posts 1216 karma points
    May 29, 2013 @ 22:04
    Steve
    0

    Got it! Thanks for taking the time to explain this to me. I realy appreaciate it!

    If I wanted to apply the ankle to one of the earlier pages how would that have looked? Just to make sure I am clearly understanding this.

  • Steve 472 posts 1216 karma points
    May 29, 2013 @ 22:36
    Steve
    0

    So you can't inject the content on the same template as where you define the content? Like this?

      
      <asp:ContentPlaceHolder Id="headContent" runat="server">
      </asp:ContentPlaceHolder>
    </asp:content>
    
    <asp:content ContentPlaceHolderId="bodyContent" runat="server">
        <div id="category-content">
        <umbraco:Item field="categoryContent" runat="server" />
        </div>
      <umbraco:Macro Alias="NewsCategory" runat="server"></umbraco:Macro>
    
    <asp:ContentPlaceHolder Id="bodyContent" runat="server">
    </asp:ContentPlaceHolder>
    
    
    <asp:ContentPlaceHolder Id="ankle" runat="server">
        <!-- Insert default "ankle" markup here -->
    </asp:ContentPlaceHolder>
    
    </asp:content>
    
    
        <asp:content ContentPlaceHolderId="ankle" runat="server">
        <div class="sliderBar">
            <p class="sliderHead">By the Numbers</p>
        <umbraco:Macro Alias="AnkleSlider" runat="server"></umbraco:Macro>
        </div>    
    </asp:content> 
    
  • lothar 25 posts 99 karma points
    Jun 05, 2013 @ 00:29
    lothar
    0

    Don't understand what you mean by the earlier pages to make an example. If your still in some trouble, explain a bit further.

    Basicly, you just need to add a ContentPlaceHolder on a page so a nested page can use it otherwise it can't display content.

    ---------------

    On your second post:

    You can't use a placeholder that you defined on the same template, they are for the nested pages.

    You can add the content just above/after the placeholder like this, so a nested page will have the sliderbar + the possibility to add an ankle after that.

    <asp:content ContentPlaceHolderId="bodyContent" runat="server">
        <div id="category-content">
            <umbraco:Item field="categoryContent" runat="server" />
        </div>
       
        <umbraco:Macro Alias="NewsCategory" runat="server"></umbraco:Macro>

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

        <!-- content from removed ankle control -->
        <div class="sliderBar">
            <p class="sliderHead">By the Numbers</p>
            <umbraco:Macro Alias="AnkleSlider" runat="server"></umbraco:Macro>
        </div> 

        <asp:ContentPlaceHolder Id="ankle" runat="server">
        <!-- Insert default "ankle" markup here -->
        </asp:ContentPlaceHolder>
    </asp:content>
  • Steve 472 posts 1216 karma points
    Jun 05, 2013 @ 15:03
    Steve
    0

    So, content is only rendered on the template on which the content is defined? And there has to be a constant nesting back up the template tree (with ContentPlaceHolder)  to where the location on the page is that you need the content positioned? I hope I explained this question correctly. Thanks for your help.

  • lothar 25 posts 99 karma points
    Jun 11, 2013 @ 22:10
    lothar
    1

    Indeed, content is only rendered on the template where it is defined, like the eample above with the sliderbar.

    And there has to be a constant nesting back up the template tree with ContentPlaceHolders & the use of Content controls.

Please Sign in or register to post replies

Write your reply to:

Draft