bem / bh

BH template engine
http://bem.github.io/bh/
MIT License
68 stars 31 forks source link

Strange behaviour or I'm doing it wrong #57

Closed xdghcnt closed 10 years ago

xdghcnt commented 10 years ago

https://gist.github.com/xdghcnt/1253e5f518215577fe22 As you can see, I want my test-block contained two logical sections that don't appear in the output, and it works as I planned: a1 a2 a3 b1 b2 b3 Then I try to append some more elements in next level of defenition: https://gist.github.com/xdghcnt/013d17c183e60a897e64 And I get this: b1 b2 b3 a2 a3 b1 b2 b3 b4 b5 b6

So I have to use workaround like this for now: https://gist.github.com/xdghcnt/cb688b5d0751cc27eeae (First I used ctx._somekey to pass value to next level and it was really ugly, but now it seems not bad and may be even better than construction that producing described bug or smth.)

Also, this example works ok: https://gist.github.com/xdghcnt/4aeb2d2f4c3c7d63d5b9

mishanga commented 10 years ago

First of all, don't ever try to use non-declarated fields of ctx (especially underscored), they can be changed of even disappear.

Second, return is a hack. It should be used at the end of the chain. It's a bad idea to redefine templates with return inside. If you really want it, use ctx.stop()

But the right way is to use native API, such as ctx.content(), and reset wrap-nodes with ctx.tag(false). In this case you'll get non-broken bemjson-tree. Like this: https://gist.github.com/mishanga/15b0846b26976ac3ebdb

Good luck!

xdghcnt commented 10 years ago

Didn't know about it tag(false), thanks!

mishanga commented 10 years ago

My bad: https://github.com/enb-make/bh/issues/58