gpt4 book ai didi

javascript - 用于元标签和标题标签的 Jinja 模板?

转载 作者:行者123 更新时间:2023-12-03 06:04:45 25 4
gpt4 key购买 nike

我是 Jinja 模板的新手。在下面的 HTML 中,两个元标记和标题标记的内容包含字母“A”。我需要创建另外三个 html 文件,其中一个文件中的标记中的“A”替换为“B”,另一个文件中替换为“C”,最后一个文件中替换为“D”。我该如何在 Jinja 中执行此操作?有没有办法创建包含这些元标记和标题标记的代码块以插入下面的主 HTML 中?如何使用 Javascript 指定每个页面顶部需要使用什么字母?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="robots" content="noindex, nofollow">
<meta name="description" content="Let us help you with your "A" needs. Get "A" today.">
<meta name="keywords" content="A">
<title>"A" Quote</title>
<script src="raven.min.js"></script>
<script>Raven.config('https://getsentry.com/90500').install();</script>
<link rel="stylesheet" type="text/css" href="/css/vendor.css">
<link rel="stylesheet" type="text/css" href="/css/main.css">
</head>
<body itemscope itemtype="">
<div id="navigation"></div>
<div id="my_page"></div>
<div id="footer"></div>
<!-- Our scripts -->
<script type="text/javascript" src="/js/vendor.js"></script>
<script type="text/javascript" src="/js/sem.js"></script>
</body>
</html>

最佳答案

您还可以将元部分定义为 macro .

{% macro meta_header(value='A') -%}
<meta name="description" content="Let us help you with your {{value}} needs. Get {{value}} today.">
<meta name="keywords" content={{value}}>
<title>{{value}} Quote</title>
{%- endmacro %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% meta_header('B') %}
<script src="raven.min.js"></script>
<script>Raven.config('https://getsentry.com/90500').install();</script>
<link rel="stylesheet" type="text/css" href="/css/vendor.css">
<link rel="stylesheet" type="text/css" href="/css/main.css">
</head>
<body itemscope itemtype="">
<div id="navigation"></div>
<div id="my_page"></div>
<div id="footer"></div>
</body>
</html>

在任何其他文件中,您可以导入宏(如果需要):

{% from 'main.html' import meta_header %}

关于javascript - 用于元标签和标题标签的 Jinja 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39603085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com