Copied to clipboard

Flag this post as spam?

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


  • Dan Wellman 20 posts 40 karma points
    Apr 17, 2011 @ 11:33
    Dan Wellman
    0

    Help with uComponents MNTP

    Hi,

    I have a series of unique document types for some sidebar boxes of content - each box has a unique document type and a unique template.

    I have installed MNTP so that the site admin can choose which box(es) they want displayed on any given page.

    I also have a macro that gets the content of the picked box(es)

    So far, I can pick a box and the contents of the box (the values entered in the properties in the back-office content section for that particular box) are dumped in the page, so everything appears to be wired up correctly. However, the contents is essentially just one long text string.

    How can I get the page to apply the template for the box that was picked when it is rendered to the page?

    Do I need to use a custom macro for each box? How would I then use the correct macro depending on which box was picked?

    Many thanks :)

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 17, 2011 @ 17:36
    Lee Kelleher
    0

    Hi Dan,

    Sounds like the missing piece to your puzzle is umbraco.library.RenderTemplate ... however there's a little gotcha - it doesn't work when you call it from XSLT! :-(

    It definitely works from a .NET user-control (not sure about Razor - not tried to call it from there yet) ... so if could hook up a .NET user-control to your macro and use the following code...

    <%@ Control Language="C#" %>
    
    <script runat="server">
        public string NodeIds { get; set; }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.NodeIds))
            {
                var output = new StringBuilder();
                var nodeIds = this.NodeIds.Split(',');
    
                foreach (var nodeId in nodeIds)
                {
                    var renderedPage = umbraco.library.RenderTemplate(nodeId);
                    if (!string.IsNullOrEmpty(renderedPage))
                    {
                        output.Append(renderedPage);
                    }
                }
    
                this.ltrlOutput.Text = output.ToString();
            }
        }
    </script>
    
    <asp:Literal runat="server" ID="ltrlOutput" />

    Don't take this code as solid/stable ... there are easy ways to break it - like unpublishing a node, etc. but you can add various checks to it, etc.

    For an alternate suggestion, take a read of Hendy's blog post on how he tackles sidebar-widgets: http://blog.hendyracher.co.uk/sidebar-widgets-with-umbraco-v4/

     

    Let us know how you get on.

    Cheers, Lee.

  • Dan Wellman 20 posts 40 karma points
    Apr 17, 2011 @ 22:40
    Dan Wellman
    0

    Hi Lee,

    Many thanks, I tried creating a usercontrol with the suggested code. I had to make a minor change to get the code to run, using Int32.Parse(nodeId) in the RenderTemplate() method, but this produces no output on the page.

    Using RenderTemplate() in XSLT is almost working, it does get the content from the box and display it on the page correctly as intended using the correct template, but it seems to stop other <umbraco:Item>s that follow it from working...

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Apr 18, 2011 @ 00:18
    Chriztian Steinmeier
    1

    Hi Dan,

    I recently published an article with an alternate (but very clean) way to handle this, all from XSLT - using separate templates (of the XSLT kind - not entire masterpages) for each of the Document Types you need rendered. Don't know if it'll suit your setup, though - but might be worth a look for future projects?

    /Chriztian

  • Dan Wellman 20 posts 40 karma points
    May 22, 2011 @ 21:37
    Dan Wellman
    0

    Have been using this with XSLT, it's fine on all pages except for the home page because on all other pages the side bar is the very last umbraco item/macro on the page.

    On the home page, with the layout, the side bar is nt the last thing, there are other <umbraco:Item>s after the side bar but they are not rendered (I guess because of the XSLT issues Lee mentioned above)

    Would using razor instead of XSLT fix this? Any tips on the razor to use? I did have a go at writing a razor script for it, but the best I could get was for it to not render anything at all (as opposed to rendering razor script errors!)

     

Please Sign in or register to post replies

Write your reply to:

Draft