I have posted my problem in this post but I haven't been able to solve it. I decided to create this post and explain my problem as best as I can.
This is my Template and doc type structure:
This is my Content structure:
The pages Species, Wellbeing and Society are Main Content Page Doc Types. The About Us & Contact and Blog have their own repective doc types.
The idea is that the editor can insert several different ContentBlocks for each species and they will be all displayed when a species is selected.
I have a basic understanding of Master Pages and I thought by doing this it would work:
On my Home Template I have:
<body> <!-- this is the main navigation menu --> <div> <umbraco:Macro Alias="TopLevelNavigation" runat="server"></umbraco:Macro> </div>
<!-- These are the types of pages that will be displaying, only one at a time. --> <asp:ContentPlaceHolderId="MainContentPlaceHolder" runat="server" />
The problem is that the content inside the Block Content Template is never shown.
On the previous thread it was talked about doing a macro that loops over the child nodes of the species and then lists it's contents. I have made an atempt at it but it's not working very well. I did this macro:
Now it does show the contents I want, but, when I choose just the species page, it lists the titles from the child nodes because of the <h2><xsl:value-of select="@nodeName"/></h2>.
I'm guessing the macro I did is far from optimal but my understanding of XSLT is very limited.
Thank you for reading this and I hope someone can help me.
I'm not an xslt guru, but I think you are always writing out whatever the children on the current node is; try limiting this to nodes of type 'ContentBlock
eg change
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
to be
<xsl:for-each select="$currentPage/ContentBlock [@isDoc and string(umbracoNaviHide) != '1']">
Also your ContentBlock DocType doesn't have to inherit from 'Master Content Page' doc type to make it work, it's likely the ContentBlock doesn't need to have the same properties as 'Master Content Page' which it currently gets by inheritance, only the properties that need to be repeated in the macro...
If you're not comfortable with XSLT, then the Razor approach maybe simpler to pick up...
<xsl:for-each select="$currentPage/ * [@isDoc and string(umbracoNaviHide) != '1']">
to
<xsl:for-each select="$currentPage/ContentBlock/ * [@isDoc and string(umbracoNaviHide) != '1']">
Makes it not work anymore and nothing is shown. I'm really confused about this. I thought it would work with the Content PlaceHolders like in ASP.NET but that not seems to be the case. I guess I'll have to look into the Razor approach.
Nested Templates
Hello!
I have posted my problem in this post but I haven't been able to solve it. I decided to create this post and explain my problem as best as I can.
This is my Template and doc type structure:
This is my Content structure:
The pages Species, Wellbeing and Society are Main Content Page Doc Types. The About Us & Contact and Blog have their own repective doc types.
The idea is that the editor can insert several different ContentBlocks for each species and they will be all displayed when a species is selected.
I have a basic understanding of Master Pages and I thought by doing this it would work:
On my Home Template I have:
<body>
<!-- this is the main navigation menu -->
<div> <umbraco:Macro Alias="TopLevelNavigation" runat="server"></umbraco:Macro> </div>
<!-- These are the types of pages that will be displaying, only one at a time. -->
<asp:ContentPlaceHolder Id="MainContentPlaceHolder" runat="server" />
<asp:ContentPlaceHolder Id="BlogContentPlaceHolder" runat="server" />
<asp:ContentPlaceHolder Id="AboutUsContentPlaceHolder" runat="server" />
</body>
On the Main Content Page Template I have:
<asp:Content ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<!-- 2nd level navigation list -->
<umbraco:Macro Alias="2ndLevelNavigation" runat="server" />
<!-- ------------------------- -->
<!-- inserting the description of the page -->
<div class="text_descrip">
<umbraco:Item field="textDescription" runat="server" />
</div>
<!-- ------------------------------------- -->
<!-- block goes here -->
<asp:ContentPlaceHolder Id="ContentBlockPlaceHolder" runat="server" >
</asp:ContentPlaceHolder>
<!-- end of block -->
</asp:Content>
On the Content Block Template I have:
<asp:Content ContentPlaceHolderID="ContentBlockPlaceHolder" runat="server">
<umbraco:Macro Alias="DisplayContentBlock" runat="server"></umbraco:Macro>
<div><umbraco:Item field="blockText" runat="server" /></div>
<div><umbraco:Item field="blockQuote" runat="server" /></div>
</asp:Content>
The problem is that the content inside the Block Content Template is never shown.
On the previous thread it was talked about doing a macro that loops over the child nodes of the species and then lists it's contents. I have made an atempt at it but it's not working very well. I did this macro:
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
<h2><xsl:value-of select="@nodeName"/></h2>
<p><xsl:value-of select="blockText"/></p>
<p><xsl:value-of select="blockQuote"/></p>
</xsl:for-each>
</xsl:template>
And I inserted it here:
Main Content Page Template:
<asp:Content ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<!-- 2nd level navigation list -->
<umbraco:Macro Alias="2ndLevelNavigation" runat="server" />
<!-- ------------------------- -->
<!-- inserting the description of the page -->
<div class="text_descrip">
<umbraco:Item field="textDescription" runat="server" />
</div>
<!-- ------------------------------------- -->
<!-- block goes here -->
<asp:ContentPlaceHolder Id="ContentBlockPlaceHolder" runat="server" >
<umbraco:Macro Alias="DisplayContentBlock" runat="server" />
</asp:ContentPlaceHolder>
<!-- end of block -->
</asp:Content>
Now it does show the contents I want, but, when I choose just the species page, it lists the titles from the child nodes because of the <h2><xsl:value-of select="@nodeName"/></h2>.
I'm guessing the macro I did is far from optimal but my understanding of XSLT is very limited.
Thank you for reading this and I hope someone can help me.
Cheers
I'm not an xslt guru, but I think you are always writing out whatever the children on the current node is; try limiting this to nodes of type 'ContentBlock
eg change
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
to be
<xsl:for-each select="$currentPage/ContentBlock [@isDoc and string(umbracoNaviHide) != '1']">
Also your ContentBlock DocType doesn't have to inherit from 'Master Content Page' doc type to make it work, it's likely the ContentBlock doesn't need to have the same properties as 'Master Content Page' which it currently gets by inheritance, only the properties that need to be repeated in the macro...
If you're not comfortable with XSLT, then the Razor approach maybe simpler to pick up...
Changing from:
<xsl:for-each select="$currentPage/ * [@isDoc and string(umbracoNaviHide) != '1']">
to
<xsl:for-each select="$currentPage/ContentBlock/ * [@isDoc and string(umbracoNaviHide) != '1']">
Makes it not work anymore and nothing is shown. I'm really confused about this. I thought it would work with the Content PlaceHolders like in ASP.NET but that not seems to be the case. I guess I'll have to look into the Razor approach.
You've got an additional / in your xpath statement after the ContentBlock alias name
Try changing
<xsl:for-each select="$currentPage/ContentBlock/ * [@isDoc and string(umbracoNaviHide) != '1']">
to
<xsl:for-each select="$currentPage/ContentBlock [@isDoc and string(umbracoNaviHide) != '1']">
also I'm assuming your alias name is 'ContentBlock'
When I leave out the "/" I get an error when saving the xslt.
But I think that does not matter now because I looked into Razor and was able to make it work. I made this razor inline macro:
<umbraco:Macro runat="server" language="cshtml">
<ul>
@foreach (var item in @Model.ContentBlock.Where("Visible"))
{
<li><h2>@item.Name</h2></li>
<p>@item.blockText</p>
<p>@item.blockQuote</p>
}
</ul>
</umbraco:Macro>
And it is working as intended! Thank you for you help, it has pointed me in the right direction! :)
cool, not everyone would agree, but the razor is much easier to work out than the xslt :-)
is working on a reply...