[Question] Modifying Template for web app

agolangf · · 491 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi guys, I was trying to make a dummy blog as practice with the golang web app development system. I am doing everything from scratch just using html and text/template. For the blog, I was trying to add a comment section to my site. However, I reached an impasse on actually listing the comments for a post.</p> <p>My idea was that I would have each post as a JSON file with all the relevant information, and I would have a template for general posts. I have a form to submit comments on the template. I figured that I could add comments to the JSON file for each article, but I am a bit unsure on how to modify the template to add comments. Right now, my template just has the ability to load the first comment. Is there a way to modify templates dynamically?</p> <p>Thanks!</p> <hr/>**评论:**<br/><br/>stone_henge: <pre><p>I&#39;m not sure what your specific question is, but in a template you may iterate over slices (or any pipeline) of values with the <code>range</code> action. The <code>html/template</code> documentation has a good example of this: <a href="https://golang.org/pkg/html/template/#example_" rel="nofollow">https://golang.org/pkg/html/template/#example_</a></p> <p>In general, the documentation for <code>text/template</code> should get you started with fully understanding the possible template actions.</p></pre>greenlanternfifo: <pre><p>Wow this is great thanks. I was going through the documentation for an example like this but was having trouble. Thank you!</p></pre>

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

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