Copied to clipboard

Flag this post as spam?

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


  • David Conlisk 432 posts 1008 karma points
    Nov 09, 2012 @ 15:52
    David Conlisk
    0

    Insert n chunks of content into tinyMCE using XSLT macro

    Hi all,

    I would like to create an XSLT macro which the content manager can use to insert n panels of content into the richtext editor. The xslt would insert the required markup for the panels to display nicely on the front end (doesn't need to render in tinyMCE).

    My problem is that the macro parameter types are pretty restricted. Ideally each panel would have a panel name, heading text and richtext in the body. Also, the number of panels should be arbitrary (ideally).

    At the moment the basic solution using what's in Umbraco natively is to define my properties long-hand (e.g. title1, title2, ..., titlen, heading1, heading2, ..., headingn, content1, content2, ..., contentn) and then deal with them in the xslt, also long hand (because they are macro parameters I don't see how I could use a loop?). This seems a bit daft and I wouldn't like anyone to see the code ;) Also the content field is only plain text (textMultiline).

    Any ideas?

  • Chris Koiak 700 posts 2626 karma points
    Nov 09, 2012 @ 15:57
    Chris Koiak
    1

    Hi David,

    If you create a template for each of your panels you can call umbraco.RenderTemplate from within your xslt. You would then create a macro (that wraps the xslt) with a page picker property. Therefore the editor can insert the Panel macro and select which panel it should render.

    There's a similar example of this in the current StandardWebsite package where the panels on the right are rendered using xslt and RenderTemplate.

    Cheers,

    Chris

  • Tim 1193 posts 2655 karma points c-trib
    Nov 09, 2012 @ 15:58
    Tim
    1

    I think you'll run into a problem trying to have richtext in macro parameters is that having multi-line text in a macro embed parameter causes the macro parser to die, as does having things like double quotes. We tried something similar in the past and it didn't work properly.

    I've done something in the past where I've had a number of panels at the bottom of the page that had title, image, link and text and I've handled that by using the Embedded Content DataTypw which covered everything I needed it to (although I don't think it does Rich Text). If you wanted to have the user choose where the panels appear you could add a macro that they could embed in the richtext editor that renders the panels that you defined in the Embedded Content page property (I've done that before as well).

  • David Conlisk 432 posts 1008 karma points
    Nov 09, 2012 @ 16:33
    David Conlisk
    1

    Thanks guys!

    I knew there had to be a better way! What I've done:

    1. Used the Repeatable Custom Content v2 datatype to create my ContentPanels datatype, with name, heading and richtext content fields

    2. Added a property to my documenttype using my new ContentPanels datatype, called Panels. This allows content managers to define the content panels they need right on the page where they will be displayed. For my purposes content panels are not reusable across pages on the site.

    3. Created a macro which can be used in the richtext editor. This displays any Panels that exist in the current page (if they exist). 

    Easy peasy!

    Here is the macro code - this can handle n content panels, no nasty copy-pasted code chunks, beautiful ;)

     <xsl:template match="/">
    
        <xsl:apply-templates select="$currentPage/contentPanels/items/item" mode="showPanel"/>
    
    </xsl:template>
    
    
    
    <xsl:template match="item" mode="showPanel">
    
        <!-- output the panel -->
    
        <div class="panel">
    
            <div class="title">
    
                <xsl:value-of select="data[@alias='name']"/>
    
            </div>
    
            <h2>
    
                <xsl:value-of select="data[@alias='headingText']"/>
    
            </h2>
    
            <xsl:value-of select="data[@alias='bodyText']" disable-output-escaping="yes"/>
    
        </div>
    
    </xsl:template>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies