Skip to content Flash-fx website
flash-fx logo image1
flash-fx logo image2
Simple solutions to complex problems. Historical swordsmanship Great online resource and forums relating to Maya and 3D.
Home << Tutorials << Plone << Simple python page template

Simple python page template

How to create a simple page template that calls a python script and displays the results in plone.
  • In the ZMI navigate to
    • Portal Skins -> Custom
  • Now using the right hand dropdown add a 'Page Template'
    Give it the ID of 'shortname_tidy_display' and click the 'Add and edit' button. Now replace the existing code with that displayed below:
  • Now you need to create the python script that will be called from near the bottom of the template (you will see it where it says em tal:content="here/shortname_tidy")

    In the ZMI go back into Portal Skins -> Custom and from the dropdown on the right create a 'script (python)'. Give it the id 'shortname_tidy' and click the 'Add and Edit' button.
    Now remove any existing code and paste what is below in:
    • # Example code:
      
      # function that takes a string and removes any spaces and underscores
      def shortname_tidy(string):
          newstring = string
          newstring = newstring.replace(' ','')
          newstring = newstring.replace('_','')
          newstring = newstring.lower();
      
          return newstring
      
      # string to be changed
      test1 = ' Hello World_ hope you_are good  '
      return shortname_tidy(test1)
      
  • If you look at the code here there is a string called test1 with spaces and underscores in. This script calls the shortname_tidy function, removes the whitespaces and underscores and returns the result to the calling page template (shortname_tidy_display in this case).
    Now go to your Plone site and call the page template - e.g, www.plone.org/shortname_tidy_display This will output the template with the tidied up python string - showing 'HelloWorldhopeyouaregood'.