Reputation: 1463
Is there any way of writing an array that's defined within a jade template with line breaks and indendations, purely for ease of reading reasons.
For example, something like this:
- var array = [
- ['a','b','c','d','e','f','g','h','i','k','l','m','n'],
- ['a','b','c','d','e','f','g','h','i','k','l','m','n'],
- ['a','b','c','d','e','f','g','h','i','k','l','m','n'],
- ['a','b','c','d','e','f','g','h','i','k','l','m','n']
- ];
I've seen this answer about multiple lines in attribute values, but I don't think I can use the same answers here.
Upvotes: 0
Views: 2095
Reputation: 688
repeat of this question : Multi-Line Array Literal
You can use the -
as a block. (adding any white spaces after the -
will not work however, new line needs to follow immediately)
-
var array = [
'a',
'b'
];
Upvotes: 1
Reputation: 6898
There is currently no elegant way to do this. You could work around your problem by using a variable for each array line
- var a1 = ['a','b','c','d','e','f','g','h','i','k','l','m','n'];
- var a2 = ['a','b','c','d','e','f','g','h','i','k','l','m','n'];
- var a3 = ['a','b','c','d','e','f','g','h','i','k','l','m','n'];
- var a4 = ['a','b','c','d','e','f','g','h','i','k','l','m','n'];
- var array = [a1, a2, a3, a4];
Or if you prefer a one dimensional array
- var array = [];
- array.push('a','b','c','d','e','f','g','h','i','k','l','m','n');
- array.push('a','b','c','d','e','f','g','h','i','k','l','m','n');
- array.push('a','b','c','d','e','f','g','h','i','k','l','m','n');
- array.push('a','b','c','d','e','f','g','h','i','k','l','m','n');
These are just work arounds since there is no elegant syntax to achieve this in jade currently.
Upvotes: 3