doufan6886 2015-10-27 20:08
浏览 33

Beego模板呈现局部

Is there a functionality to render partial templates in the Beego? I used this functionality in RoR.

Ruby on Rails partials: Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.

Example from RoR:

<!-- html.erb -->
<h1>New zone</h1>
<%= render partial: "form", locals: {zone: @zone} %>

and

<!-- _form.html.erb -->
<%= form_for(zone) do |f| %>
  <p>
    <b>Zone name</b><br>
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.submit %>
  </p>
<% end %>
  • 写回答

1条回答 默认 最新

  • dongpan1871 2015-11-04 03:02
    关注

    Yes, though they are not explicitly referenced as partials in the documentation, you can compose templates like you described. From the documentation for views.

    {{template "header.html"}}
      Logic code
    {{template "footer.html"}}
    

    Because Beego is an MVC framework, it will automatically look for your "partials" in the views directory.

    If you had another subdirectory called views/base then your partial would look like this:

    {{template "base/header.html" .}}
    

    A good reference implementation that will provide more examples in the context of a real world app, check out the wetalk project on github

    评论

报告相同问题?

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)