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

Your first Python script in Umbraco

Nearly every book about programming begins with a basic "hello world"-code snippet. This book is no exception, so:

  1. Open Umbraco and go to the Developer section
  2. Right click the "Python Files"-node in the node tree and select "Create".
  3. A window opens where you can type in a filename. Do this, but without the ".py" file extension.
  4. Click on the newly created python-script file - now you're ready to create your first script.
  5. Type in:

    s = "Hello World"
    print s


    Click the Save-icon. Umbraco will notify you of any typing mistakes, so don't worry about those :)
    If you are familiar with C#, Java, C++ or similar you might wonder where the ending semicolon has gone? I didn't forget it. Python simply doesn't require that.

    Lets move on..
  6. Next - create a new macro by right clicking the "Macro"-node just above "Python Files". Call it whatever you like.
  7. Open the macro you created - on the appearing screen you can see the usual controls for referencing macros to XSLT files, .NET controls etc. Just below those you find the python dropdown where your python file should show up. Select it and click Save.
  8. The final step is insert the macro on your page. Depending on your selections you selected when you created the macro you can choose to insert it in your templates - or directly on your page. If all goes well, you should see your page greeting the world ;-)