SE7ENSKY / jade2php

Unlock Jade for PHP! Convert Jade templates into raw PHP templates. CLI tool and JavaScript API. Test covered.
43 stars 10 forks source link

Concatenating variables in attributes #37

Open Edo78 opened 8 years ago

Edo78 commented 8 years ago

Hi, maybe I'm doing something wrong but if I try to compile this

each related in ['a', 'b']
    img(class="bottle_"+related+".jpg", src="bottle_"+related+".jpg")

I get

<?php
if (array(
    'a',
    'b'
)):
    foreach (array(
        'a',
        'b'
    ) as $related):
        $■['related'] = $related;
?><img src="bottle_"+related+".jpg"<?php
        attr_class(add("bottle_", $related, ".jpg"));
?>/><?php
    endforeach;
endif;
?>

As you can see class and srcare compiled with different values ... Right now I use an ugly workaround declaring variable for every concatenation I need eg. - var bottle="bottle_"+related+".jgp"but this is way far from ideal

Is it a bug or am I missing something?

janwirth commented 8 years ago

The expression inside the src attribute is not being transpiled correctly. Looks like a bug. @ivankravchenko, do you concur?

ivankravchenko commented 8 years ago

Sounds like original Jade code should look like:

each related in ['a', 'b']
    img(class="bottle_#{related}.jpg", src="bottle_#{related}.jpg")

Is it processed with original Jade correctly?

Anyway, jade2php should not generate incorrect output, so it's a bug.

Edo78 commented 8 years ago

using "string #{variable}" syntax solve my problem