简体   繁体   English

全局液体变量可在自定义过滤器中使用

[英]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 . 就我而言,我有一个appointments模型,范围booking_reference于一个网站,该网站具有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. 我可以将其传递到render液体方法中,并在模板中使用它。 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. 更新:我研究了Liquid具有的Drop类,以及其中没有方法的方法。

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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