Break Line in @Foreach Can any méthode to get ouput of this Foreach looking like
U15-U11-U16
not
U15- U11- U16
without spacing \
@foreach ($users as $use)
@if ($use->ref)U{{$use->id}}-@endif
@endforeach
Wrap the out put in trim()
put everything on the same line. Line breaks in html are translated to single space
trim('U'.$use->id.'-') or put the whole if statement in the trim.
But @Snapey has a very good point. They need to output all on one line. Otherwise the space will be there.
@Snapey i tried with this before but not working if there is a condition @if
Give me error of
syntax error, unexpected 'if' (T_IF)
working only when we have a simple foreach
@jekinney i use #trim but with no change
Hi @Ftoi , I had a similar problem with the @if not working when next to other text/output and the only way I solved it was to use php if instead e.g.
@foreach ($users as $use)<?php if ($use->ref) { echo 'U' . $use->id . '-' } ?>@endforeach
A blade file IS after all just a php script :)
@MarkLL
i copy this code but give me error
syntax error, unexpected '<'
but when i breakline between @foreach and <?php if
@foreach ($users as $use)
<?php if ($use->ref) { echo 'U' . $use->id . '-' } ?>
@endforeach
it's work but still with spacing between U15- U16
Hi @Ftoi , try putting the whole thing in a block. As others have said, the line break is adding the space.
e.g.
<?php
foreach ($users as $use) {
if ($use->ref) {
echo 'U' . $use->id . '-';
}
}
?>
There is definitely issues finding the tokens (@... ) in some instances.
@MarkLL it's work maybe when you do #foreach with '@' it's give a spacing automatically either when you used in block
Please sign in or create an account to participate in this conversation.