Copied to clipboard

Flag this post as spam?

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


  • Allan Petersen 1 post 21 karma points
    Oct 18, 2009 @ 19:27
    Allan Petersen
    0

    Create a Template dynamically

    Hi,

    I'm a total newbie at umbraco, and I really need some help.

    I'm trying to create a page, where I could define an "Object" to be put in on my page dynamically. 

    Template 1 is the "Object", eg. it holds html to be used multiple times on a web page. Template 1 had matching document type that is used to fill out fields of the "Object":

    Template 1:

    <%@ Master Language="C#" MasterPageFile="/masterpages/Event.master" AutoEventWireup="true" %> <asp:Content ContentPlaceHolderId="EventContentPlaceHolder" runat="server"> <div class="post"> <div class="title"> <h2><umbraco:Item field="Event_Title" runat="server"></umbraco:Item></h2> <p><small><umbraco:Item field="Event_dato" runat="server"></umbraco:Item></small></p> </div> <div class="entry"> <umbraco:Item field="Event_Tekst" runat="server"></umbraco:Item> </div> <p class="links"><umbraco:Item field="Event_Links" runat="server"></umbraco:Item> </p> </div> </asp:Content>

    Template 2 holds Template on, and acts as a master page...

    <%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %> <asp:Content ContentPlaceHolderId="MasterContentPlaceHolder" runat="server"> <!-- start content --> <div id="content"> <asp:ContentPlaceHolder runat="server" id="EventContentPlaceHolder" /> </div> <!-- end content --> </asp:Content>

    The thing is, I would like to - from the Content pane - to be able to add multiple Templates 1's just by using the fields I wite in on the Content pane... But every time I have to create a new page, fill out the fields, and then its a separate page, but I want it in just one page!? 

    I don't know if it's the right place to ask, or if it's impossible to achieve, but please help!

    I use umbraco v 4.0.0 (Assembly version: 1.0.3327.20280)

    And ASP.NET 2.0

    Windows 7 (Final version) and IIS 7

    Thanks

    Allan


  • Petr Snobelt 923 posts 1535 karma points
    Oct 19, 2009 @ 09:40
  • Edward Dudley 80 posts 121 karma points
    Oct 19, 2009 @ 14:55
    Edward Dudley
    0

    The repeatable custom content (as suggested by Petr) would work - you could also do this by adding child nodes (in the content section) to your page.

    In the template for the page you want to call add a macro that links to an XSLT file.  Paste the code below into your XSLT:

                <xsl:for-each select="$currentPage/node">
                    <xsl:variable name="currentPageId" select="current()/@id" />
                    <xsl:value-of select="umbraco.library:RenderTemplate($currentPageId, current()/@template)" disable-output-escaping="yes"/>
                </xsl:for-each>

    Now when you load the main page (the one with the child nodes) the templates for each of the child nodes will be rendered where you placed your macro.

    I hope this helps!  It's probably easiest to give it a go.  If you get stuck post back and I'll try to write up some more detailed instructions (if you choose this approach).  This is only one of the ways this could be done and I guess its up to you to choose which is the most appropriate for you!

Please Sign in or register to post replies

Write your reply to:

Draft