Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade - Using Block inside script tag

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.

like image 762
Arruda Avatar asked Jun 09 '12 23:06

Arruda


1 Answers

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.

like image 89
Arnaud Rinquin Avatar answered Oct 21 '22 10:10

Arnaud Rinquin