Pylons / pyramid_layout

Pyramid add-on for managing UI layouts.
Other
24 stars 26 forks source link

How to get the the 'view' global renderer variable in the panel #29

Open geohuz opened 10 years ago

geohuz commented 10 years ago

I found in the panel template there is no 'view' renderer global variable there, I was trying to get it through the introspectable but failed. Is there an easy way to get it?

chrisrossi commented 10 years ago

Hi George,

I assume this is because there is some helper method on a class based view that you want to call in the template? 'view' isn't available, but 'panel' is. You could always use a class based panel and have your helper function on the panel class. You could probably even mix view_config and panel_config on different methods of the same class, so you could have panels and views in the same class which would share the same helper methods.

Panels can also accept arbitrary keyword arguments, so you could always pass the view from the main template to the panel.

Chris

On Mon, Jun 23, 2014 at 7:33 AM, geohuz notifications@github.com wrote:

I found in the panel template there is no 'view' renderer global variable there, I was trying to figure out how to get it through the introspectable but failed. Is there a easy to get it?

— Reply to this email directly or view it on GitHub https://github.com/Pylons/pyramid_layout/issues/29.

geohuz commented 10 years ago

Thanks Chris, now I have another issue to get the current panel callable name, basically I want to display the function or callable name in the page, when I use panel renderer variable, it displays something like bound method LayoutManager.render_panel of <pyramid_layout.layout.LayoutManager object at 0x10950d3d0

chrisrossi commented 10 years ago

Hi George, I goofed. 'panel' is the render_panel callable used to render panels inside of a template. It is not the panel currently being rendered. I would suggest looking for a different way to get that information into your page. Sorry for the confusion.

geohuz commented 10 years ago

I changed the source code in config.py, the function add_renderer_globals to this:

def add_renderer_globals(event):
    if 'panel' in event:
        event['panel_callable'] = event['panel']
    request = event['request']
    ...

I'm not sure if this is the best way to fix my problem, but it works.