Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Jun 07, 2011 @ 14:32
    Martin
    0

    Repeat Content Block - Newbie Question

    Hi there,

    Complete newbie to xslt (working my way through umbraco.tv).

    I have a page where i want to display multiple addresses.

    I want the user to be able to select "add new address" and then be able to fill in relevent fields. I get this is a docutype, where i create the fields only once.

    But how do I set up a UI to allow the user to add an address. I guessing a macro.

    Can anyone point me in the direction of a tutorial?

     

    Thanks

    Martin

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 07, 2011 @ 14:54
    Tom Fulton
    0

    Hi Martin,

    There's a few different approaches you can use:

    - Sub Documents
    This would involve creating a Document Type called "Address" and allowing it to be created under your page.  The Address doctype would have all the relevant fields and the user could then create as many as they like beneath your page.  You could then easily loop through them with an XSLT macro on your main page like so:

    <xsl:for-each select="$currentPage/Address">
    <xsl:value-of select="address1"/><br/><xsl:value-of select="concat(city, ', ', state, ' ', zip)"/>
    </xsl:for-each>

    - "Repeatable Datatype"
    There are a few packages available that offer the "repeating" functionality you are looking for.  Embedded Content would probably suit you well.  Basically you would create an Embedded Content Datatype, add your Address fields to it, then add the datatype to your page's Document Type.  The Embedded Content control allows editors to add as many addresses as they like right from the page.  The control stores it's data in XML so it's easy to access in XSLT similar to the above example.

    <xsl:for-each select="$currentPage/yourEmbeddedContentPropertyAlias/data/item">
    <xsl:value-of select="address1"/><br/><xsl:value-of select="concat(city, ', ', state, ' ', zip)"/>
    </xsl:for-each>

    - Macro & Macro Container
    As you mentioned you could possibly use a macro.  You would set all the address fields up as Macro Parameters, then use the Macro Container datatype to allow the user to add addresses.  This is similar to #2 which I think is a bit cleaner and more flexible though.

    - Documents outside the Tree
    Similar to #1, you could use Documents to store Addresses, then use something like MultiNodeTreePicker from uComponents to "pick" them from your page.  You could store the Addresses outside of your main content tree, in something like a "Configuration" or "Backoffice" node if you wish.  This would make it easy to re-use them in other pages if needed.

     

    I personally would use #2 with Embedded Content.  The only caveat is it doesn't support advanced datatypes like drop down fields, only the basic Textbox/Textbox multiple/Checkbox/etc, so you couldn't have a "State" or "Country" dropdown, not sure if that is an issue for you or not.  If you need to use advanced datatypes I would reccomend #1 or #4 depending on your situation.

    Hope this helps get you started - let us know how you get along.

    -Tom

  • Martin 278 posts 662 karma points
    Jun 08, 2011 @ 09:01
    Martin
    0

    Thanks Tom,

    That really helped. I got a bit confused when creating the macro, but finally got the naming correct.

    Thanks Again.

Please Sign in or register to post replies

Write your reply to:

Draft