RenderMacroContent, Xslt works - but not Python macros
Hi!
Short story : umbraco.library.RenderMacroContent does only work with Xslt macros, not with DLR ones. Any reason for that? ("Error loading DLR script" - nothing more, nothing in the log either)
Long story :
I have two uses for this:
Simple way to get data via a Macro with Base:
To be able to get data in a simple and conveniant way particularly from jQuery (for example autocompletes) I made a small Base class that renders a macro with name sent as a parameter (and it allows macro parameters aswell).
It works beautifully with Xslt macros, but it wont render Python macros, which is pretty sad, because that was what I was looking for in the first place.
Use Macro Content Data Type to let the editor select "Widgets"
I wanted to use that, but I need to render the macros in a macro since I like them to be able to add any number of Macros. Same thing here : Xslt works fine, but Python does not.
Oh. Just found it documented in the source "Python and .ascx based macros will not render properly, as viewstate is not included". Ah, bummer. :-/ But hey, whats the need of Viewstates for Python macros? :-o
I give up for now, not being sure I have the right source versions and dlls make this a battle against shadows. I need more knowledge of the source before tackling this once again.
I sincerely hope someone else will take a look at it though. Executing Python files from C# + from Base could be a winner thing. Imagine setting up and easy editing a simple Python script to return whatever dynamic content to jQuery.
Ah, stupid / stubborn of me. It's simple as render the macros within a very basic template with a macro that renders another macro, then everything works fine as Umbraco template engine takes care of everything for us. No need of Base for this.
/Happy again (3 o clock in the night) :)
So I created a python macro :
from umbraco import library macroTemplate = """ """ macroAlias = library.RequestQueryString("macroAlias") pageId = library.RequestQueryString("pageId") # be careful not to run macros that are not supposed to be run this way # if macroAlias in ("DoRunThis", "DoRunThat", ...) print library.RenderMacroContent(macroTemplate.format(macroAlias=macroAlias), pageId)
And called it from within an otherwise empty template named RenderMacro, after that I can use this url
RenderMacroContent, Xslt works - but not Python macros
Hi!
Short story : umbraco.library.RenderMacroContent does only work with Xslt macros, not with DLR ones. Any reason for that? ("Error loading DLR script" - nothing more, nothing in the log either)
Long story :
I have two uses for this:
Simple way to get data via a Macro with Base:
To be able to get data in a simple and conveniant way particularly from jQuery (for example autocompletes) I made a small Base class that renders a macro with name sent as a parameter (and it allows macro parameters aswell).
/Base/BaseMacros/Render/MyMacroName/1100/param1=1¶m2=2
It works beautifully with Xslt macros, but it wont render Python macros, which is pretty sad, because that was what I was looking for in the first place.
Use Macro Content Data Type to let the editor select "Widgets"
I wanted to use that, but I need to render the macros in a macro since I like them to be able to add any number of Macros. Same thing here : Xslt works fine, but Python does not.
Regards / Jonas
Oh. Just found it documented in the source "Python and .ascx based macros will not render properly, as viewstate is not included". Ah, bummer. :-/ But hey, whats the need of Viewstates for Python macros? :-o
I'm trying to find out why umbraco.library.PythonExecuteFile does not work
This GetType in python.cs (umbraco.presentation) returns a null value
System.Type EngineType = asm.GetType("IronPython.Hosting.PythonEngine");
which gives us an error here
Engine = System.Activator.CreateInstance(EngineType);
I dont know any more, leaving it there for further research by me or anyone else.
I give up for now, not being sure I have the right source versions and dlls make this a battle against shadows. I need more knowledge of the source before tackling this once again.
I sincerely hope someone else will take a look at it though. Executing Python files from C# + from Base could be a winner thing. Imagine setting up and easy editing a simple Python script to return whatever dynamic content to jQuery.
Ah, stupid / stubborn of me. It's simple as render the macros within a very basic template with a macro that renders another macro, then everything works fine as Umbraco template engine takes care of everything for us. No need of Base for this.
/Happy again (3 o clock in the night) :)
So I created a python macro :
And called it from within an otherwise empty template named RenderMacro, after that I can use this url
www.mysite.com/RenderMacro?macroAlias=WhateverCoolMacro&pageId=1109
It's good for jQuery-stuff and also for a quick way to test macros (especially Python that does not have the visualizer).
brilliant - thanks for this!
is working on a reply...