pyramid_layout icon indicating copy to clipboard operation
pyramid_layout copied to clipboard

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

Open geohuz opened this issue 10 years ago • 4 comments

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?

geohuz avatar Jun 23 '14 11:06 geohuz

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 [email protected] 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.

chrisrossi avatar Jun 23 '14 14:06 chrisrossi

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

geohuz avatar Jun 24 '14 03:06 geohuz

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.

chrisrossi avatar Jun 24 '14 14:06 chrisrossi

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.

geohuz avatar Jul 03 '14 02:07 geohuz