Laravel blade syntax for @if/@endif spacing issueif
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
add a comment |
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
add a comment |
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
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
laravel syntax laravel-blade
asked Nov 13 '18 at 17:13
Vlad AgriVlad Agri
1715
1715
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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 ...
add a comment |
Try this:
@if(...) {{ 'abc' }} @else
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
add a comment |
The correct syntax is:
@if(...)
abc
@else
cde
@endif
I never saw unwanted spaces with this one.
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
add a comment |
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}}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 ...
add a comment |
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 ...
add a comment |
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 ...
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 ...
answered Nov 13 '18 at 17:18
Vlad AgriVlad Agri
1715
1715
add a comment |
add a comment |
Try this:
@if(...) {{ 'abc' }} @else
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
add a comment |
Try this:
@if(...) {{ 'abc' }} @else
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
add a comment |
Try this:
@if(...) {{ 'abc' }} @else
Try this:
@if(...) {{ 'abc' }} @else
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
add a comment |
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
add a comment |
The correct syntax is:
@if(...)
abc
@else
cde
@endif
I never saw unwanted spaces with this one.
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
add a comment |
The correct syntax is:
@if(...)
abc
@else
cde
@endif
I never saw unwanted spaces with this one.
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
add a comment |
The correct syntax is:
@if(...)
abc
@else
cde
@endif
I never saw unwanted spaces with this one.
The correct syntax is:
@if(...)
abc
@else
cde
@endif
I never saw unwanted spaces with this one.
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
add a comment |
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
add a comment |
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}}
add a comment |
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}}
add a comment |
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}}
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}}
answered Nov 27 '18 at 15:56
MrEversMrEvers
5911
5911
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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