I hope i wrote it correctly, as i remember when you have an array options in javascript these are called object literals. I have a problem i can't find how to use @if statement in object literal. I have a small site and everything is located inside welcome.blade.php template so i don't have separate javascript file, the function that i use is just at the bottom of the template inside tags. So here is the whole function that i have
<script>
var employees = [
@foreach ($workers->chunk(20) as $chunk)
[
@foreach ($chunk as $worker)
{
innerHTML:'<div class="container-fluid full-height"><div class="row full-height"><div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 full-height"><div class="person-info"><blockquote><h1>{{ $worker->first_name }} {{ $worker->last_name }}</h1>{{{ $worker->function !== '') ? <footer>{{ $worker->function }}</footer> : '' }}}</blockquote></div></div><div class="col-xs-5 col-sm-5 col-md-5 col-lg-5 col-lg-offset-1 col-md-offset-1 col-sm-offset-1 full-height"><div class="person-photo"><img class="img-responsive" src="thumbs/{{ $worker->image }}" /></div></div></div></div>',
src:"thumbs/{{ $worker->thumbnail }}"
},
@endforeach
],
@endforeach
]
</script>
As you can see i need to get all the info from $workers
inside innerHTML
and that should be output as html content, but as some fields will be empty in database so i need to write @if statement if those fields are not empty to display some code
{{{ $worker->function !== '') ? '<footer>{{ $worker->function }}</footer>' : '' }}}
But i can't get it how to get the if statement inside innerHTML
content to work.
EDIT: The closest that i got it working is like this:
'{{ $worker->function ? "<footer> $worker->function </footer>" : "" }}' +
But this just renders the output completely with <footer>
so now i have like
John Doe <footer>
Quality manager </footer>