1

I have a following problem. I am checking if arrays are empty and if they are i am hiding specific elements in table. This implementation adds only 1 class but is there a way to add multiple without using javascript?

<table @if(empty($a)) class="hide_a"@endif
    @if(empty($aa)) class="hide_aa"@endif
    @if(empty($aaa)) class="hide_aaa"@endif>
1
  • Cannot use javascript because dompdf does not support it Commented Jun 9, 2020 at 13:03

3 Answers 3

3

The Problem is, that a html element can only have one class attribute. Simply check the value inside the class attribute

<table class="{{ empty($a) ? 'hide_a' : '' }} {{ empty($aa) ? 'hide_aa' : '' }} {{ empty($aaa) ? 'hide_aaa' : '' }}">
Sign up to request clarification or add additional context in comments.

Comments

2

Yes, you can do it as below.

    <table class="@if(empty($a)) hide_a @endif 
@if(empty($aa)) hide_aa @endif 
@if(empty($aaa)) hide_aaa @endif">

1 Comment

Do not use a ternary operator for this. when you use a ternary operator it is the case where you check if..else.. and you don't need else part.
2
    <table class="@if(empty($a))  hide_a @endif 
       @if(empty($aa)) hide_aa @endif 
       @if(empty($aaa)) hide_aaa @endif">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.