Written by Simon Justesen     For umbraco versions: umbraco3.0

How-to
A new feature in the Umbraco 3 branch is the integration of IronPython which is a .NET implementation of the Python programming language. I'll start out easy and occasionally expand this book with more tips 'n tricks

Contents

IronPython and the Umbraco API

One of the strengths of the IronPython implementation in Umbraco is that you are able to use every corner of the Umbraco API.

Let us say you want to display a list of membergroups. You can add membergroups by going to the members-section, rightclick the members node and click 'create' add a few membergroups this way.

Now you want to display them on a page. You can archive this by writing just 4 (!) lines of code. You could probably do the same with C# and even XSLT, but that's a matter of preference.

Put this inside a python script and attach the file to a macro:

from umbraco.cms.businesslogic.member import *

print "Membergroups present:" + "<br>"

for membergroups in MemberGroup.GetAll:
    print membergroups.Text + "<br>"

Explanation: The first line fetches the umbraco.cms.businesslogic.member namespace and imports every class in it. The second line displays a string (line of text) and a break; the third line loops through an array of membergroup objects while the fourth line displays the content.

Pay close attention to the indented print-line in the for-in loop. This is the IronPython/Python way of structuring code. If those lines were not indented, the interpreter would not see them as a part of the for-in block

To be continued...