How to Use Template Blocks in Go 1.6

blov · · 867 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I had to research a bit to learn how to use the template blocks in Go 1.6 so I wrote up a quick article.</p> <p><a href="http://www.josephspurrier.com/how-to-use-template-blocks-in-go-1-6/">http://www.josephspurrier.com/how-to-use-template-blocks-in-go-1-6/</a></p> <hr/>**评论:**<br/><br/>togamans: <pre><p>Thanks, this is super helpful. What do you use templates for at your company? I built a dashboard with templates as a pre-alpha demo, but never again. I only use them for dynamic content in email notifications I generate now. </p></pre>motojo: <pre><p>When I build websites, I use templates for each of the pages. You can see how I use templates in my project on Github: <a href="https://github.com/josephspurrier/gowebapp/tree/master/template" rel="nofollow">https://github.com/josephspurrier/gowebapp/tree/master/template</a></p></pre>togamans: <pre><p>yea, when the site got more complex (ie just more things on the page), the templates became unwieldy and the data objects I had to pass in for dynamic content werent great either. I&#39;m in the process of reimplementing the web UI in either angular or react, powered by a json API. Thanks for linking to your project!</p></pre>motojo: <pre><p>No problem! Using a angular or react with an API is great way to go. That way you have an API that can be used for web or mobile. I think I need to modify my view package to allow templates to be in different folders so it&#39;s easier to organize and manage.</p></pre>saturn_vk: <pre><p>The article is incorrect regarding the limits of the template section. You can omit a define action and still render correctly. In order to do so, you will have to place an <strong>empty</strong> define action for any template that might be missing, in the base template or any other that will always be included:</p> <p><a href="https://github.com/urandom/readeef/blob/master/templates/base.tmpl#L20" rel="nofollow">https://github.com/urandom/readeef/blob/master/templates/base.tmpl#L20</a></p></pre>motojo: <pre><p>Ah, very interesting. I didn&#39;t know you could add define actions to the base template when using the template action. So I guess the main difference between <strong>template</strong> and <strong>block</strong> is when using <strong>template</strong>, define actions are required or else it will throw an error. Are there any other differences?</p></pre>: <pre><p>[deleted]</p></pre>guenther_mit_haar: <pre><p>Look on saturn_vk code - you can define the empty sections <strong>in</strong> the base template to avoid this problem</p></pre>gohacker: <pre><p>Yes. And it wasn&#39;t clear to me since I read about the new template blocks, what are the benefits apart from introducing a new syntax just for the heck of it?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

867 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传