Best method to make parts of CSS class names dynamic with php?

Because inside of double quotes is not possible i do it this way:

<button id=<php> echo "trtmntacc-header-" . get_row_index(); </php> aria-expanded="false" aria-controls=<php> echo "trtmntacc-panel-" . get_row_index(); </php> data-accordion-header class="accordion__header">My Button</button>

Is there a better way?

Oh no. The second approach doesn’t work either.

For now i am using a PHP Smart Action echoing the complete <button ....> and then again a PHP Smart Action for the </button>.

It works but is uncomfortable and makes it impossible to change the button attributes inside of the PG Panels.

I am sure, there is a better solution. Right @Emmanuel @matjaz ?

Okay… after staying away some time and come back to this problem here’s how it works:

<button id="<?php echo 'trtmntacc-header-' . get_row_index(); ?>">My Button Text</button>

Was just a matter of single and double quotes… phew… :face_with_peeking_eye:


@MichelyWeb congrats for figuring it out! :slight_smile:

Another way would be:

<button id="trtmntacc-header-<?php echo get_row_index(); ?>">Hello</button>

This avoids having to use nested quotes.

1 Like

Right. It’s better doing it that way.

I’m sure i tried all of this in the beginning and couldn’t get it to work. Therefore this complicated detour to the obvious solution. :slight_smile: