Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plone 4: Passing arguments to view class (BrowserView)

Tags:

python

plone

I have been following this URL to help me create template views using BrowserView. So far, it works OK and I am able to create a template with a view class.

What I need to know is whether it is possible to pass arguments to methods inside the view class i.e.

from Products.Five import BrowserView

class Html(BrowserView):
    def still_dreaming(self):
        msg = "Some people are still dreaming"
        return msg

I need to add an extra argument to the still_dreaming function and process it inside the function like this:

def still_dreaming(self, some_arg):
        msg = some_arg + " Some people are still dreaming"
        return msg

Then I need to call the function and pass an argument to it from my template. Something like this:

<p tal:content="view/still_dreaming(item/publication_date)"></p>

Unfortunately, I do not know the correct way of passing arguments to the method. Any pointers will be greatly appreciated.

EDIT: item/publication_date is just some variable and could be anything. It has just been defined previously.

like image 666
Frankline Avatar asked Jan 31 '12 11:01

Frankline


1 Answers

Yes.

  <p tal:content="python:view.still_dreaming(item.publication_date)" />

You can use TAL traversing syntax (default), Python syntax or String syntax in TAL expressions.

http://collective-docs.readthedocs.org/en/latest/functionality/expressions.html

like image 176
Mikko Ohtamaa Avatar answered Oct 23 '22 02:10

Mikko Ohtamaa