{{include}} 里不能用变量有没有办法workaround?

2 views
Skip to first unread message

Chunlin Zhang

unread,
Sep 8, 2015, 3:02:28 AM9/8/15
to uli...@googlegroups.com
我这里实际的情况如下
通过settings导入相关的配置:
BUILDER_SCHEME = [
    #id,sort_num,scheme class
    (100,100,"linci.builder_scheme.shell.Shell"),
]
配置里linci.builder_scheme.shell.Shell是一个class
class Shell(object):
    name = "Shell"
    template_new = "LinCi/inc_shell_new.html"

    @staticmethod
    def get_steps():
        return {}
实际使用的时候通过settings取到class,然后想动态include相关的模版文件
{{include scheme_class.template_new}}

看文档0.4以后改造了模版引擎以后就不支持了,在这种情况下如果想要达到我的目的有什么办法吗?

Chunlin Zhang

unread,
Sep 8, 2015, 9:26:39 AM9/8/15
to uli...@googlegroups.com
我现在想了个办法,干脆读到要include的文件内容然后在模版里 {{<<}} 进去

limodou

unread,
Sep 8, 2015, 10:55:22 AM9/8/15
to uliweb
这是一种办法,就是出错了可能不好调试。0.4的修改是因为模板做成了先编译,后渲染,所以象include这种在编译时就要处理的,就没有办法在渲染时再动态处理了。

我现在想了个办法,干脆读到要include的文件内容然后在模版里 {{<<}} 进去
--
-- ----
Project : https://github.com/limodou/uliweb
doc : http://limodou.github.com/uliweb-doc
---
You received this message because you are subscribed to the Google Groups "Uliweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uliweb+un...@googlegroups.com.
To post to this group, send email to uli...@googlegroups.com.
Visit this group at http://groups.google.com/group/uliweb.
To view this discussion on the web visit https://groups.google.com/d/msgid/uliweb/CAG2rzAn_zhUBQ6Z2e0nv2o77SzzZjtX%3DBsjwrYQ%3DCO2ALuQ67w%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: https://github.com/limodou/uliweb
My Blog: http://my.oschina.net/limodou

Chunlin Zhang

unread,
Sep 8, 2015, 7:27:59 PM9/8/15
to uli...@googlegroups.com
貌似你没有其他的建议了?

Chunlin Zhang

unread,
Sep 8, 2015, 11:17:36 PM9/8/15
to uli...@googlegroups.com
我现在这样用貌似可以:
{{<<application.template(scheme_class.template_new)}}
不过template的env要怎么给才能用到那些预置的变量如request呢?
{{<<application.template(scheme_class.template_new,env=request.environ)}} 这样好像不行,在include的模版里{{print request}}出错

Chunlin Zhang

unread,
Sep 8, 2015, 11:21:34 PM9/8/15
to uli...@googlegroups.com
搞错了,不加 env 参数就可以访问 request 了

limodou

unread,
Sep 9, 2015, 12:43:58 AM9/9/15
to uliweb
暂时没有其它的建议了,另一种做法就是分开不同的模板


For more options, visit https://groups.google.com/d/optout.

Chunlin Zhang

unread,
Mar 30, 2016, 3:24:45 AM3/30/16
to uli...@googlegroups.com
我这里碰到一个问题就是如果
{{<<application.template(scheme_class.template_view,vars={"builder":builder,"scheme_class":scheme_class})}}
里产生的内容有 block,那这个block是没有作用的
比如我在用 application.template里返回的html里写的block并不能有覆盖该block的作用,如果把block写在外面才可以

Chunlin Zhang

unread,
Mar 30, 2016, 3:47:21 AM3/30/16
to uli...@googlegroups.com
具体地说:

如果是
{{block content_main}}
{{block builder_ext}}{{end builder_ext}}
{{end content_main}}

{{include "LinCi/inc_shell_view.html"}}
这样,如果LinCi/inc_shell_view.html里有builder_ext,则能替换前面的builder_ext

而如果用
{{block content_main}}
{{block builder_ext}}{{end builder_ext}}
{{end content_main}}

{{<<application.template("LinCi/inc_shell_view.html",vars={"builder":builder,"scheme_class":scheme_class})}}
那么LinCi/inc_shell_view.html里的builder_ext,则不能替换前面的builder_ext

能不能让 application.template 产生的部分也一样可以做block替换呢?

limodou

unread,
Mar 30, 2016, 9:29:40 AM3/30/16
to uliweb
为什么要这样做呢?现在uliweb的模板是先编译,后运行的。这种动态的处理会破坏编译的处理过程,而且目前也无法支持,因为在编译时无法预测后面的内容。
> --
> -- ----
> Project : https://github.com/limodou/uliweb
> doc : http://limodou.github.com/uliweb-doc
> ---
> You received this message because you are subscribed to the Google Groups
> "Uliweb" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to uliweb+un...@googlegroups.com.
> To post to this group, send email to uli...@googlegroups.com.
> Visit this group at https://groups.google.com/group/uliweb.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/uliweb/CAG2rzAm6o%2B1Gqceztuxg2pWsEg7%3DA8PeRyCPe0DZi-g3QayMiw%40mail.gmail.com.

Chunlin Zhang

unread,
Mar 30, 2016, 10:43:08 AM3/30/16
to uli...@googlegroups.com
我要做到的大概是这样的,我写了一个通用的界面,比如一个自动构建的配置界面,但是希望使用这个模块的人可以自行扩展根据不同的类型自行变化的界面
本来想用 include 模板文件的方式
现在想一想,可以用动态改变 response.template 的方式,这样更好,而且也没有 application.template的问题,之后试试看了

Reply all
Reply to author
Forward
0 new messages