客户端(JavaScript)Django /类似Jinja的模板继承 [英] Client-Side (JavaScript) Django/Jinja-like template inheritance

查看:109
本文介绍了客户端(JavaScript)Django /类似Jinja的模板继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式来进行模板继承到一组 .html 文件。

I'm looking for a way to do template inheritance to a group of .html files I have.

假设我有一个 base.html 文件,它具有我网站所有页面(例如页眉,页脚等)的通用HTML。每个页面,包括主(索引)页面需要从此模板HTML文件继承。

Let's say I have a base.html file which has the common HTML for all pages of my website, i.e. header, footer, etc. . Each page, including the main (index) page, needs to inherit from this template HTML file.

现在,这在服务器端可以使用 Django的Jinja模板langauge 。但这对我来说不是很好的解决方案。我的HTML页面远程存储,我无法控制存储它们的服务器。这必须在客户端进行,无论是否使用JavaScript。

Now, this is doable on the server-side using Django's Jinja template langauge. But this is not a good solution for me. My HTML pages are stored remotely and I have no control over the server storing them. This must be done client-side, with or without JavaScript.

有人问关于这一点,而我发现的唯一半解决方案是使用胡子的

Somebody asked about this before, and the only half-baked solution I found was to use Mustache's partials, which doesn't really do the job.

有没有人知道在客户端这样做的方式? / p>

Does anybody know of a way to do this on the client-side?

推荐答案

1。
是的,使用Dustjs,您可以使用模板从常用的基本模板
继承其大部分内容。

1. Yes, with Dustjs you can "have a template inherit the bulk of its content from a common base template".

检查在Dustjs文档中,这里: Dustjs ,块和内联部分部分。

Check out the Dustjs docs, here: Dustjs, the "Blocks and Inline Partials" section.

(我发布了相关问题的答案,这里是: https:/ /stackoverflow.com/a/12432034/694469

(I posted an answer to a related question, here: https://stackoverflow.com/a/12432034/694469 )

2。
还有一些工作正在进行添加模板继承到 Handlebars ,看另一个答案我的这个问题的其他版本: https://stackoverflow.com/a/12432490/ 694469

链接到此GitHub问题: https://github.com/wycats/handlebars.js/issues/208 ,这个博文:手柄的模板继承

It links to this GitHub issue: https://github.com/wycats/handlebars.js/issues/208, and this blog post: Template Inheritance for Handlebars

这篇关于客户端(JavaScript)Django /类似Jinja的模板继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆