Copied to clipboard

Flag this post as spam?

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


  • Dan Okkels Brendstrup 101 posts 197 karma points
    Jan 19, 2012 @ 09:06
    Dan Okkels Brendstrup
    0

    Caching output of umbraco.library:Item in XSLT macro?

    I've got a site full of text pages with standard rich text editors, and I'd like to cache the output of the macro that outputs title + date + RTE content.

    If I do this:

    <xsl:value-of select="textContent" disable-output-escaping="yes"/>

    ...then everything caches as expected. But no embedded macros in the RTE content work, including Contour forms. To solve that problem, I use the "Item" extension function instead:

    <xsl:value-of select="umbraco.library:Item(@id, 'textContent')"/>

    ...but then when I turn on caching, nothing is ouput for that field. Is it not possible to cache the output of that function? And is it possible to cache RTE content with embedded Contour forms at all?

    Thanks in advance.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 10:28
    Rodion Novoselov
    0

    Hi. That's right - "xsl:value-of" just output the raw value of the "textContent" so no embeded macro will work this way. Actually, I think that a possible workaround could be to create for this purpose not an XSLT but a user-control macro and show this field inside it by embeding the "<umbraco:Item field="textContent" .../>" control inside it.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 10:39
    Rodion Novoselov
    0

    And also I'm not certain that you can use the Item method the way you're doing. It's not a static method, so it cannot be used from within XSLT as an extension method. (And, frankly speaking I even don't know what this method is for)

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Jan 19, 2012 @ 12:54
    Dan Okkels Brendstrup
    0

    umbraco.library:Item can indeed be used as an XSLT extension function (cf. http://our.umbraco.org/wiki/reference/umbracolibrary/item), and it does a perfect job of outputting RTE content including any embedded macros. So all is fine there. It just won't output anything when the macro in question is cached.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 13:46
    Rodion Novoselov
    0

    Hmmm. Live and learn...  :-) Thanks for usefull information on the "Item" method. I've tried your scenario and realised that as soon as caching is on some NullReference exception happens while rendering. I haven't yet found out why (unfortunately I don't have a debug build of my umbraco version on hand right now), but I'm still curious about the case. I'll try to investigate it today a bit later.

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Jan 19, 2012 @ 14:07
    Dan Okkels Brendstrup
    0

    Huh, that sounds like a bug, then. Thanks for checking that out! If you discover anything else, I'd love to know!

    Forget to mention it, btw, but I'm experiencing the problem on a 4.7.0 install.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 14:09
    Rodion Novoselov
    0

    I've tried it on the latest one (4.7.1.1) and the issue is still there.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 16:31
    Rodion Novoselov
    0

    Hi again. Well, I runned it under the debugger and there's definitely a bug. In the scenario that we're talking about rendering of the Item control skips OnInit and OnLoad stages (it just creates an instance of the Item control class and than calls Render()). Meanwhile OnInit and OnLoad methods contain some significant initialisation that if skipped prevents the control from normal rendering afterwards. That's not the case when caching is off since the rendering process is different.

    I've also tried the scenario that I proposed earlier and made sure that it's completely workable. I created a very simple user control (just two lines):

    <%@ Control Inherits="System.Web.UI.UserControl" %>
    <umbraco:Item runat="server" Field="bodyText" />

    Than I created a user control macro from this control and turn its caching on. Everything including caching works than all right (the "bodyText" field of course includes some HTML + embeded macro), so you could try this way as well.

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Jan 20, 2012 @ 12:43
    Dan Okkels Brendstrup
    0

    Wow, thanks for checking that out, Rodion! The technical details are out of my league, so I don't think I could do a very precise bug report, but if you feel like reporting it, that'd be awesome.

    And great that it is solvable with a user control in the interrim. That means I'll have to do some ugly hackery in my XSLT to wrap the bodyText field in the correct markup, but that'll have to do. Thanks for the help!

Please Sign in or register to post replies

Write your reply to:

Draft