1

I have mustache :

my mustache

after I render, there are 4 divs (which are the same 2 div).

html

I want to display only 2 div or remove duplicate div, can someone help me?

code :

{{#bya_jsa}}
    {{#jasa}}

        {{#bya_jsa}}
            {{#no}}
                <div id="divbiayapekerjaan" form-no="{{no}}">
            {{/no}}
        {{/bya_jsa}} 

            <div class="form-group">
                <label><b>Jasa</b></label>
                <input type="text" name="bya_js[][jasa]" value="{{jasa}}" class="form-control" placeholder="Masukkan jasa yang ada" required="required">
            </div>

    {{/jasa}}
    {{#by_mulai}}       
            <div class="form-group">
                <label><b>Dimulai</b></label>
                <input type="text" name="bya_js[][by_mulai]" value="{{by_mulai}}" class="form-control uang" placeholder="Contoh; Rp 10.000.000" required="required">
            </div>
    {{/by_mulai}}
    {{#by_sampai}}
            <div class="form-group">
                <label><b>Sampai</b></label>
                <input type="text" name="bya_js[][by_sampai]" value="{{by_sampai}}" class="form-control uang" placeholder="Contoh; Rp 60.000.000" required="required">
            </div>
            <hr>
            <br>

            {{#bya_jsa}}
                {{#no}}
                    </div>
                {{/no}}
            {{/bya_jsa}}  

    {{/by_sampai}} 
{{/bya_jsa}}
Muhammad Ashraf
  • 54
  • 1
  • 13
  • Hello Muhammad Ashraf. May I trouble you to post the code as part of the question in text form? This will help others help you faster and respond more completely. Just add four spaces before each line where the code is being placed in the post. – Christopher Stevens Oct 03 '18 at 02:43
  • 1
    ok ,thank you for responding to my question , and sorry for my bad english ,hahaha – Muhammad Ashraf Oct 03 '18 at 02:49

1 Answers1

0

I think one potential answer you are looking for is found here, a way to handle if/else statements.

OR:

Refactor to include a dynamic "by" value:

...
<div class="form-group">
    <label><b>{{by_name}}</b></label>
    <input type="text" name="bya_js[][{{by_val}}]" value="{{by_val}}" class="form-control" placeholder="{{placeholder}}" required="required">
</div>
...

I chose by_name as the formatted name, by_val as the value that was more system-looking, and placeholder as that related value. This would allow you to only create one form instead of several. You would need to set by_name and by_val a little differently ahead of time.

Christopher Stevens
  • 1,214
  • 17
  • 32