Jade-在脚本标记内使用块 [英] Jade - Using Block inside script tag

查看:107
本文介绍了Jade-在脚本标记内使用块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Jade的 blocks extends 用于node.js项目,其思想是:

layout.jade:

head
    script
        $(document).ready(function() {
        block js_doc_ready
            //here goes the doc ready
        });

index.jade:

block js_doc_ready
    alert('hello!');
    alert('one more js line code');
    alert('end my js doc ready for this view');

这会给我一个index.html,像这样:

...
<head>
    <script type="text/javascript">
            $(document).ready(function() {
                alert('hello!');
                alert('one more js line code');
                alert('end my js doc ready for this view');         
            });
    </script>
</head>
...

但是,当我看到结果时,'block js_doc_ready'不被视为Jade块. 另外,即使它被认为是一个块,也不会将"alert('hello!);'视为一个Jade标签.

这是我以前在django模板中所做的事情,但是在玉器中带有所有这些标签,并且没有做纯HTML的自由,我仍然觉得做这件事有点太奇怪了.

解决方案

Jade不翻译'style'和'script'代码中的内容.永远不会.

有效的方法是基于我给另一个问题的答案(使用样式元素,但基本上是相同的).

!!!
head
  title Hello jade
  | <script type='text/javascript'>
  | $(document).ready(function() {
      block js_doc_ready
  | });
  | </script>

这种方式:jade将包含HTML'script'标签和$ .ready行,但还将包含您的代码块.

Hi there I'm trying using Jade's blocks and extends for a node.js project, and the ideia is to have something like this:

layout.jade:

head
    script
        $(document).ready(function() {
        block js_doc_ready
            //here goes the doc ready
        });

index.jade:

block js_doc_ready
    alert('hello!');
    alert('one more js line code');
    alert('end my js doc ready for this view');

This would give me a index.html like this:

...
<head>
    <script type="text/javascript">
            $(document).ready(function() {
                alert('hello!');
                alert('one more js line code');
                alert('end my js doc ready for this view');         
            });
    </script>
</head>
...

But when I see the result, the 'block js_doc_ready' is not considered a Jade block. Also, even if it was considered a block, the "alert('hello!);' wouldn't be considered a, but a Jade tag.

This is something that I used to do in django template, but in jade with all this tags, and no liberty to do pure html I still find it a little too strange to make this things.

解决方案

Jade do not translate what's inside 'style' and 'script' code. Never.

What will work is based on an answer I gave to another question (using a style element but that's basically the same).

!!!
head
  title Hello jade
  | <script type='text/javascript'>
  | $(document).ready(function() {
      block js_doc_ready
  | });
  | </script>

This way : jade will include the HTML 'script' tags and $.ready lines but will also include your block.

这篇关于Jade-在脚本标记内使用块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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