Laravel blade syntax for @if/@endif spacing issueif












0















what is the similar blade syntax for the following code?



<?php if(...):?>abc<?php else:?>cde<?php endif;?>


the code
@if(...) abc @else .... is no good as it ads a space before and after the "abc" the code @if(...)abc@endif (no spacing before and after html string) generates error ...



Thanks










share|improve this question



























    0















    what is the similar blade syntax for the following code?



    <?php if(...):?>abc<?php else:?>cde<?php endif;?>


    the code
    @if(...) abc @else .... is no good as it ads a space before and after the "abc" the code @if(...)abc@endif (no spacing before and after html string) generates error ...



    Thanks










    share|improve this question

























      0












      0








      0








      what is the similar blade syntax for the following code?



      <?php if(...):?>abc<?php else:?>cde<?php endif;?>


      the code
      @if(...) abc @else .... is no good as it ads a space before and after the "abc" the code @if(...)abc@endif (no spacing before and after html string) generates error ...



      Thanks










      share|improve this question














      what is the similar blade syntax for the following code?



      <?php if(...):?>abc<?php else:?>cde<?php endif;?>


      the code
      @if(...) abc @else .... is no good as it ads a space before and after the "abc" the code @if(...)abc@endif (no spacing before and after html string) generates error ...



      Thanks







      laravel syntax laravel-blade






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 17:13









      Vlad AgriVlad Agri

      1715




      1715
























          4 Answers
          4






          active

          oldest

          votes


















          1














          Did a bit more research and it looks like there is no solution as there is no spaceless tag in blade. I found a solution from someone who wrapping his string in extra hml tags (so that is easy as he ads spaces before and after the tag and the string inside tag si spaceless) but in my case I just need a string no spaces before and after ... I will go the old fashion php way ...






          share|improve this answer































            0














            Try this:



            @if(...) {{ 'abc' }} @else





            share|improve this answer
























            • i thought about that but it's UGLY ;) ... also tested this does not make any difference, the spaces are still added... abc == {{ 'abc' }} the problem is still the spaces before and after the {{ }}

              – Vlad Agri
              Nov 13 '18 at 17:18













            • UGLY!! You make me laugh.. :D :D

              – Sand Of Vega
              Nov 13 '18 at 17:19











            • Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

              – sepehr
              Nov 13 '18 at 21:07



















            0














            The correct syntax is:



            @if(...)
            abc
            @else
            cde
            @endif


            I never saw unwanted spaces with this one.






            share|improve this answer
























            • yes there are spaces ... add something before the if and after the if (for example open and close brackets) and try to get the content inside near the brackets without space ... (@if(...) abc @endif ). I tis mandatory to have a space after the endif otherwise the word will not be understood by the parser. And that space is then applied to the result ... can you get a text like (abc) where the brackets are outside of the if statement and the abs is a result on the then or else branch ?

              – Vlad Agri
              Nov 15 '18 at 17:55





















            0














            I've run into similar problems with spaces.

            A workaround I use is this:

            Put your if statement into php tags



            @php
            $myVar = 'abc';
            if(...) $myVar = 'cde';
            @endphp


            and then echo the defined variable



            {{$myVar}}





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286307%2flaravel-blade-syntax-for-if-endif-spacing-issueif%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Did a bit more research and it looks like there is no solution as there is no spaceless tag in blade. I found a solution from someone who wrapping his string in extra hml tags (so that is easy as he ads spaces before and after the tag and the string inside tag si spaceless) but in my case I just need a string no spaces before and after ... I will go the old fashion php way ...






              share|improve this answer




























                1














                Did a bit more research and it looks like there is no solution as there is no spaceless tag in blade. I found a solution from someone who wrapping his string in extra hml tags (so that is easy as he ads spaces before and after the tag and the string inside tag si spaceless) but in my case I just need a string no spaces before and after ... I will go the old fashion php way ...






                share|improve this answer


























                  1












                  1








                  1







                  Did a bit more research and it looks like there is no solution as there is no spaceless tag in blade. I found a solution from someone who wrapping his string in extra hml tags (so that is easy as he ads spaces before and after the tag and the string inside tag si spaceless) but in my case I just need a string no spaces before and after ... I will go the old fashion php way ...






                  share|improve this answer













                  Did a bit more research and it looks like there is no solution as there is no spaceless tag in blade. I found a solution from someone who wrapping his string in extra hml tags (so that is easy as he ads spaces before and after the tag and the string inside tag si spaceless) but in my case I just need a string no spaces before and after ... I will go the old fashion php way ...







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 17:18









                  Vlad AgriVlad Agri

                  1715




                  1715

























                      0














                      Try this:



                      @if(...) {{ 'abc' }} @else





                      share|improve this answer
























                      • i thought about that but it's UGLY ;) ... also tested this does not make any difference, the spaces are still added... abc == {{ 'abc' }} the problem is still the spaces before and after the {{ }}

                        – Vlad Agri
                        Nov 13 '18 at 17:18













                      • UGLY!! You make me laugh.. :D :D

                        – Sand Of Vega
                        Nov 13 '18 at 17:19











                      • Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

                        – sepehr
                        Nov 13 '18 at 21:07
















                      0














                      Try this:



                      @if(...) {{ 'abc' }} @else





                      share|improve this answer
























                      • i thought about that but it's UGLY ;) ... also tested this does not make any difference, the spaces are still added... abc == {{ 'abc' }} the problem is still the spaces before and after the {{ }}

                        – Vlad Agri
                        Nov 13 '18 at 17:18













                      • UGLY!! You make me laugh.. :D :D

                        – Sand Of Vega
                        Nov 13 '18 at 17:19











                      • Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

                        – sepehr
                        Nov 13 '18 at 21:07














                      0












                      0








                      0







                      Try this:



                      @if(...) {{ 'abc' }} @else





                      share|improve this answer













                      Try this:



                      @if(...) {{ 'abc' }} @else






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 13 '18 at 17:17









                      Sand Of VegaSand Of Vega

                      1,233518




                      1,233518













                      • i thought about that but it's UGLY ;) ... also tested this does not make any difference, the spaces are still added... abc == {{ 'abc' }} the problem is still the spaces before and after the {{ }}

                        – Vlad Agri
                        Nov 13 '18 at 17:18













                      • UGLY!! You make me laugh.. :D :D

                        – Sand Of Vega
                        Nov 13 '18 at 17:19











                      • Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

                        – sepehr
                        Nov 13 '18 at 21:07



















                      • i thought about that but it's UGLY ;) ... also tested this does not make any difference, the spaces are still added... abc == {{ 'abc' }} the problem is still the spaces before and after the {{ }}

                        – Vlad Agri
                        Nov 13 '18 at 17:18













                      • UGLY!! You make me laugh.. :D :D

                        – Sand Of Vega
                        Nov 13 '18 at 17:19











                      • Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

                        – sepehr
                        Nov 13 '18 at 21:07

















                      i thought about that but it's UGLY ;) ... also tested this does not make any difference, the spaces are still added... abc == {{ 'abc' }} the problem is still the spaces before and after the {{ }}

                      – Vlad Agri
                      Nov 13 '18 at 17:18







                      i thought about that but it's UGLY ;) ... also tested this does not make any difference, the spaces are still added... abc == {{ 'abc' }} the problem is still the spaces before and after the {{ }}

                      – Vlad Agri
                      Nov 13 '18 at 17:18















                      UGLY!! You make me laugh.. :D :D

                      – Sand Of Vega
                      Nov 13 '18 at 17:19





                      UGLY!! You make me laugh.. :D :D

                      – Sand Of Vega
                      Nov 13 '18 at 17:19













                      Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

                      – sepehr
                      Nov 13 '18 at 21:07





                      Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

                      – sepehr
                      Nov 13 '18 at 21:07











                      0














                      The correct syntax is:



                      @if(...)
                      abc
                      @else
                      cde
                      @endif


                      I never saw unwanted spaces with this one.






                      share|improve this answer
























                      • yes there are spaces ... add something before the if and after the if (for example open and close brackets) and try to get the content inside near the brackets without space ... (@if(...) abc @endif ). I tis mandatory to have a space after the endif otherwise the word will not be understood by the parser. And that space is then applied to the result ... can you get a text like (abc) where the brackets are outside of the if statement and the abs is a result on the then or else branch ?

                        – Vlad Agri
                        Nov 15 '18 at 17:55


















                      0














                      The correct syntax is:



                      @if(...)
                      abc
                      @else
                      cde
                      @endif


                      I never saw unwanted spaces with this one.






                      share|improve this answer
























                      • yes there are spaces ... add something before the if and after the if (for example open and close brackets) and try to get the content inside near the brackets without space ... (@if(...) abc @endif ). I tis mandatory to have a space after the endif otherwise the word will not be understood by the parser. And that space is then applied to the result ... can you get a text like (abc) where the brackets are outside of the if statement and the abs is a result on the then or else branch ?

                        – Vlad Agri
                        Nov 15 '18 at 17:55
















                      0












                      0








                      0







                      The correct syntax is:



                      @if(...)
                      abc
                      @else
                      cde
                      @endif


                      I never saw unwanted spaces with this one.






                      share|improve this answer













                      The correct syntax is:



                      @if(...)
                      abc
                      @else
                      cde
                      @endif


                      I never saw unwanted spaces with this one.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 13 '18 at 20:38









                      common sensecommon sense

                      2,45831625




                      2,45831625













                      • yes there are spaces ... add something before the if and after the if (for example open and close brackets) and try to get the content inside near the brackets without space ... (@if(...) abc @endif ). I tis mandatory to have a space after the endif otherwise the word will not be understood by the parser. And that space is then applied to the result ... can you get a text like (abc) where the brackets are outside of the if statement and the abs is a result on the then or else branch ?

                        – Vlad Agri
                        Nov 15 '18 at 17:55





















                      • yes there are spaces ... add something before the if and after the if (for example open and close brackets) and try to get the content inside near the brackets without space ... (@if(...) abc @endif ). I tis mandatory to have a space after the endif otherwise the word will not be understood by the parser. And that space is then applied to the result ... can you get a text like (abc) where the brackets are outside of the if statement and the abs is a result on the then or else branch ?

                        – Vlad Agri
                        Nov 15 '18 at 17:55



















                      yes there are spaces ... add something before the if and after the if (for example open and close brackets) and try to get the content inside near the brackets without space ... (@if(...) abc @endif ). I tis mandatory to have a space after the endif otherwise the word will not be understood by the parser. And that space is then applied to the result ... can you get a text like (abc) where the brackets are outside of the if statement and the abs is a result on the then or else branch ?

                      – Vlad Agri
                      Nov 15 '18 at 17:55







                      yes there are spaces ... add something before the if and after the if (for example open and close brackets) and try to get the content inside near the brackets without space ... (@if(...) abc @endif ). I tis mandatory to have a space after the endif otherwise the word will not be understood by the parser. And that space is then applied to the result ... can you get a text like (abc) where the brackets are outside of the if statement and the abs is a result on the then or else branch ?

                      – Vlad Agri
                      Nov 15 '18 at 17:55













                      0














                      I've run into similar problems with spaces.

                      A workaround I use is this:

                      Put your if statement into php tags



                      @php
                      $myVar = 'abc';
                      if(...) $myVar = 'cde';
                      @endphp


                      and then echo the defined variable



                      {{$myVar}}





                      share|improve this answer




























                        0














                        I've run into similar problems with spaces.

                        A workaround I use is this:

                        Put your if statement into php tags



                        @php
                        $myVar = 'abc';
                        if(...) $myVar = 'cde';
                        @endphp


                        and then echo the defined variable



                        {{$myVar}}





                        share|improve this answer


























                          0












                          0








                          0







                          I've run into similar problems with spaces.

                          A workaround I use is this:

                          Put your if statement into php tags



                          @php
                          $myVar = 'abc';
                          if(...) $myVar = 'cde';
                          @endphp


                          and then echo the defined variable



                          {{$myVar}}





                          share|improve this answer













                          I've run into similar problems with spaces.

                          A workaround I use is this:

                          Put your if statement into php tags



                          @php
                          $myVar = 'abc';
                          if(...) $myVar = 'cde';
                          @endphp


                          and then echo the defined variable



                          {{$myVar}}






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 27 '18 at 15:56









                          MrEversMrEvers

                          5911




                          5911






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286307%2flaravel-blade-syntax-for-if-endif-spacing-issueif%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Florida Star v. B. J. F.

                              Error while running script in elastic search , gateway timeout

                              Adding quotations to stringified JSON object values