Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twig Indenting code format, not indenting correctly #4869

Open
sarelvdm opened this issue Oct 27, 2022 · 11 comments
Open

Twig Indenting code format, not indenting correctly #4869

sarelvdm opened this issue Oct 27, 2022 · 11 comments
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers PHP [ci] enable extra PHP tests (php/php.editor)

Comments

@sarelvdm
Copy link

Apache NetBeans version

Apache NetBeans 15

What happened

Im using Twig, the (IF statement does not align,

pic1
pic2

How to reproduce

Detail same as in what happened

Did this work correctly in an earlier version?

Apache NetBeans 12.6 or earlier

Operating System

Windows 10 X64

JDK

19

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

Every time you use Twig file and try to do source format.

Are you willing to submit a pull request?

Yes

Code of Conduct

Yes

@sarelvdm sarelvdm added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Oct 27, 2022
@junichi11
Copy link
Member

Please write an example code to reproduce it. Thanks!

@junichi11 junichi11 added the PHP [ci] enable extra PHP tests (php/php.editor) label Oct 27, 2022
@sarelvdm
Copy link
Author

sarelvdm commented Oct 27, 2022

Hi, thanks for responding.

The Twig conditions "IF statement or the For loop" should take priority in alignment over HTML Code.
You can align HTML code inside the Twig condition.
If the Twig condition is inside the HTML DIV the div should take priority
Untitled-1

@sarelvdm
Copy link
Author

sarelvdm commented Oct 28, 2022

@junichi11 I hope the above code and layout is to you standard

Prepared to help and test the functionality
Thank you.

@junichi11
Copy link
Member

Just wait. Please write a simple example code if possible. An expected result and an actual result, too.
NOTE: I can't promise anything. (I can't work on it soon now.)

@sarelvdm
Copy link
Author

sarelvdm commented Nov 4, 2022

Thank you @junichi11

expected result

{% block content %}
{#Im selecting between 2 routes, reason for the 2 forms, this is based on variable input}
{#The if else endif should be aligned #}

{#The twig logic alignment should take preferance above HTML except when Twig conditions "If / For" loop is used inside a html div#}

<div class="container">
    <div class="row">
        <div class="box col-8">
            <div class="card">
                <div class="card-body">
                    {% if nextmemberid == ''%}
                        <form action="{{ route('accmember',{_memberid:currentmember.memberid}) }}" method="POST">
                            <input type="hidden" name="memberid" value="{{ currentmember.memberid }}">
                    {% else %}
                        <form action="{{ route('accmember',{_memberid:nextmemberid}) }}" method="POST">
                            <input type="hidden" name="memberid" value="{{ nextmemberid }}">
                    {% endif %}
                            <input type="hidden" name="{{ csrf.key }}" value="{{ csrf.token }}">

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <div class="form-floating form-floating-group flex-grow-1">
                                        <input class="form-control{{ errors.firstname ? ' is-invalid' : '' }}" 
                                               id="firstname" name="firstname" placeholder="firstname" 
                                        {% if currentmember.firstname|trim is not empty %}
                                            value="{{ currentmember.firstname }}">
                                        {% else %}  
                                            value="{{old.firstname }}"> 
                                        {% endif %} 
                                        <label for="uafirstname">First name</label> 
                                        {% if errors.firstname %}
                                            <div class="invalid-feedback">
                                                <label for="floatingInputInvalid">{{ errors.firstname | first }}</label>
                                            </div>
                                        {% endif %}
                                    </div>
                                </div>
                            </div>
                        </form>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}

Actual result after code format used

{% block content %}

<div class="container">
    <div class="row">
        <div class="box col-8">
            <div class="card">
                <div class="card-body">
                    {% if nextmemberid == ''%}
                        <form action="{{ route('accmember',{_memberid:currentmember.memberid}) }}" method="POST">
                            <input type="hidden" name="memberid" value="{{ currentmember.memberid }}">
                        {% else %}
                            <form action="{{ route('accmember',{_memberid:nextmemberid}) }}" method="POST">
                                <input type="hidden" name="memberid" value="{{ nextmemberid }}">
                            {% endif %}
                            <input type="hidden" name="{{ csrf.key }}" value="{{ csrf.token }}">

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <div class="form-floating form-floating-group flex-grow-1">
                                        <input class="form-control{{ errors.firstname ? ' is-invalid' : '' }}" 
                                               id="firstname" name="firstname" placeholder="firstname" 
                                               {% if currentmember.firstname|trim is not empty %}
                                                   value="{{ currentmember.firstname }}">
                                        {% else %}  
                                            value="{{old.firstname }}"> 
                                        {% endif %} 
                                        <label for="uafirstname">First name</label> 
                                        {% if errors.firstname %}
                                            <div class="invalid-feedback">
                                                <label for="floatingInputInvalid">{{ errors.firstname | first }}</label>
                                            </div>
                                        {% endif %}
                                    </div>
                                </div>
                            </div>
                        </form>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}

@sarelvdm
Copy link
Author

Hi @junichi11, I found addition BUG missing closing brackets under twig when creating new <script's

  1. I found this bug <script type='text/javascript'> it doesn't create the closing tag </script>
  2. inside the <script type='text/javascript'> when using if on the else it does not create the closing } see sample code with comments
<script type='text/javascript'>
                            $(document).ready(function () {

                                $("#live_search").keyup(function () {

                                    var input = $(this).val();
                                    //alert(input);

                                    if (input != "") {

                                        $.ajax({
                                            url: '/fetchdata',
                                            type: 'POST',
                                            dataType: 'json',
                                            data: {_token: $('meta[name="csrf-token"]').attr('content'), '{{ csrf.key }}': '{{ csrf.token }}',
                                                input: input
                                            },
                                            success: function (data) {
                                                $("#searchresults").html(data);
                                            }
                                        });
                                    }else {  // if you type in the { it should also create the closing tag,
                                            
                                           } // <<<< this one  } dont get created 
       

                                });
                            });
  </script> //<<<< this closing tag don't get created, need to type manually 

@sarelvdm
Copy link
Author

@junichi11

Just wait. Please write a simple example code if possible. An expected result and an actual result, too. NOTE: I can't promise anything. (I can't work on it soon now.)

If possible, I know you under pressure. Others will also benefit from it.
You helped with the previous twig plugin, thanks... using it daily.

Thanks for your time to make NetBeans the best.

@sarelvdm
Copy link
Author

@junichi11
Please, will be greatly appreciated.

@sarelvdm
Copy link
Author

sarelvdm commented Mar 9, 2023

@junichi11 any news regarding the code formatting in Twig

@junichi11
Copy link
Member

Unfortunately, we can't fix this case from the twig module.

<div class="container">
    {% if nextmemberid == ''%}
        <form action="{{ route('accmember',{_memberid:currentmember.memberid}) }}" method="POST">
            <input type="hidden" name="memberid" value="{{ currentmember.memberid }}">
    {% else %}
        <form action="{{ route('accmember',{_memberid:nextmemberid}) }}" method="POST">
            <input type="hidden" name="memberid" value="{{ nextmemberid }}">
    {% endif %}
        </form>
</div>

If you close the HTML tag, maybe it works correctly.
e.g.

<div class="container">
    {% if nextmemberid == ''%}
        <form action="{{ route('accmember',{_memberid:currentmember.memberid}) }}" method="POST">
            <input type="hidden" name="memberid" value="{{ currentmember.memberid }}">
        </form>
    {% else %}
        <form action="{{ route('accmember',{_memberid:nextmemberid}) }}" method="POST">
            <input type="hidden" name="memberid" value="{{ nextmemberid }}">
        </form>
    {% endif %}
</div>

As a workaround:
Please use variables. NOTE I'm not an expert of twig.

{% if nextmemberid == ''%}
    {% set example = 'foo' %}
    {% set value = 'a' %}
{% else %}
    {% set example = 'bar' %}
    {% set value = 'b' %}
{% endif %}

<form action="{{ example }}" method="POST">
    <input type="hidden" name="memberid" value="{{ value }}">
</form>

@sarelvdm
Copy link
Author

sarelvdm commented May 1, 2023

thank you for trying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

No branches or pull requests

2 participants