Copied to clipboard

Flag this post as spam?

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


  • Deng 7 posts 30 karma points
    Jan 17, 2011 @ 12:47
    Deng
    0

    Any possibility of combine XSLT, Python and Razor? E.g. Macro within Macro...

    Hi,

    I have been using Umbraco for some time now, and find that XSLT is very good at generating content which across different pages, e.g. navigation, archive. Python is very good at handling basic form logic, includes contact form and newsletter signup. Now we have Razor in 4.6.1 which is elegant syntax itself, and you can kind of use C# in @ {...}, which is not ideal as it is designed to be a template engine. Just wondering is it possible to combine the goodies of different things to utilize them?

    As in XSLT search and other XSLT scripts, you can use JavaScript/C# code, in razor you can use C#, is it possible to pass information around Python & XSLT in a certain way? I know Python is running within its context, and not sure whether marshal or similar thing can make Python work within XSLT? Currently I put several Macro tag within a template to utilize them, however, I cannot control one from within another, which is a problem for me sometimes.

    Many thanks for reading and any comment you might have.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 17, 2011 @ 13:07
    Jan Skovgaard
    0

    Hi Denq

    I'm not sure how if it's possible to mix python with XSLT or XSLT and Razor. However I don't think it would make any sense to mix any of them.

    If you need something in your XSLT from some C# code I think you should really consider making an XSLT extension instead. You can learn more about XSLT extensions here: http://umbraco.org/help-and-support/video-tutorials/developing-with-umbraco/xslt-extensions/introduction-to-xslt-extensions - It's 19€ to get full access and it's worth the money :-)

    /Jan

  • Deng 7 posts 30 karma points
    Jan 17, 2011 @ 13:15
    Deng
    0

    Hi Jan,

    I have the video subscription, and still I think c# assembly is not easy to change as HTML/CSS/JavaScript/Python does... flexible is the core of dynamic & is one of the advantage of CMS itself.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 17, 2011 @ 13:36
    Jan Skovgaard
    0

    Hi Denq

    I'm not saying C# is as easy to change as the others. But from how I understand what you're asking for you can't mix the different languages into one of the others and then wrap'em up in a macro :-)

    If you need some more flexibility in your XSLT I think that extensions is the way to go.

    Just my 2 cents.

    /Jan

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 17, 2011 @ 15:42
    Jonas Eriksson
    0

    Hi Denq,

    very interesting question!

    For my development I consider Razor a replacement for both Python and Xslt. I did some tests to use Razor for forms and think it worked out pretty well. See for example http://bit.ly/fkB5r6 (the membership login script sample).

    The one thing I miss is the nice ability to import other files as Python have, for example to build a rich class structure. So that part I have to take care of with regular server side C# code.

    Umbraco.library had a nice function ExecutePython. But I think that died with version 4.0. Should not be to much of a deal to bring it back, it might even be a good excercise to do it by oneself. Dive into the source for some IMacroEngine Execute.

    Kind regards

    Jonas

    P.S. The multi-language solution can be a drawback by itself, feels a bit messy with too much of a mix on one site? And also upgrades of Umbraco might be problematic (last version of Umbraco for example had some problems combining Vb.Net and DLR languages).

  • Deng 7 posts 30 karma points
    Jan 17, 2011 @ 15:57
    Deng
    0

    Hi Jonas,

    Thank you for your reply and example of razor, my idea is in Python, still trying :)


    if requestType == "POST":
    #handle form postback
    print("Thank you for submit.")
    else:
    transform =
    XslTransform()
    #transform(currentPage)
  • Jonas Eriksson 930 posts 1825 karma points
    Jan 17, 2011 @ 16:43
    Jonas Eriksson
    0

    ok :) - something like a controller in python using any macro as view(s)? I like that! Python syntax is indeed nice.

  • Deng 7 posts 30 karma points
    Jan 17, 2011 @ 17:07
    Deng
    0

    source code of 4.6.1 confuses me... it is hard to find things I would like to read about, I searched for:

    XPathNodeIterator
    &
    umbraco.MacroEngines.DynamicNode

    But cannot find anything, strange, used to old 4.5.2 source structure, or maybe I went to totally a wrong place?!

    Sorry, please ignore, I think I downloaded & use the wrong source, I have downloaded something related to 5.0, which is MVC and totally different...

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 18, 2011 @ 10:08
  • Deng 7 posts 30 karma points
    Jan 19, 2011 @ 11:33
    Deng
    1

    Super!!!

    Thanks, Jonas and Matt.

    I have just tested to use XSLT macro within razor & python, both works! Just tested simple case, so, there maybe corner case which I have not encountered yet.

    Also call razor from python, or call python from razor are no problem at all..

    you can even call python from razor, which calls xslt (not sure if you can keep on doing so)

    experimental with calling razor/python from within xslt at the moment, the encoding, escape is a bit hard to figure out.

    for razor to call macro:


    <div>@umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"umbTopNavigation\" ></?UMBRACO_MACRO>", 1070)</div>

     

    for python to call marco:


    from umbraco import library

    print(library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"razorTest\" ></?UMBRACO_MACRO>", 1070))

     

  • Deng 7 posts 30 karma points
    Jan 19, 2011 @ 11:38
    Deng
    1

    Ok, here goes, call macro from within XSLT, python for example


            <div>
              <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;pyScriptTest&quot; &gt;&lt;/?UMBRACO_MACRO&gt;', 1070)" disable-output-escaping="yes"/>
            </div>

     

Please Sign in or register to post replies

Write your reply to:

Draft