简体   繁体   中英

Global liquid variable available in custom filters

I have built some custom filters in liquid.

The app i'm building them on has multiple sites which certain users should not be able to access. In my case I have an appointments model, scoped to a site, which has a booking_reference . I don't want users of a site being able to find appointments that don't belong to them

I can have the passed into the render liquid method and have it available within the template. This can then be passed into the filter. But this can be spoofed easily.

So my question is, how can i get a global variable available in my liquid filters.

Alternatively is there a better way to do this?

Thanks

Update: I looked into the Drop class that liquid has and methods on that don't take arguments.

You can try like this, for example
controller:

render :text => liquid.render( vars, 
    :registers => {:current_site => @current_site}
)

In place where you define fillter or tag:

context.registers[:current_site]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM