0

I have this in php:

'position' => [
			'label' => ['Pic Position', ''],
			'inputType' => 'select',
			#'default' => 'left',
			'options' => [
				'left' => 'Left',
				'right' => 'Right',
			],
		]

now i want if 'Left' is selected, that a class called left is added to a div! I cannot figure out the php syntax for that!

<div class="floating_text" <?php if ($this->position == 'left') echo 'class="left"' ?>>
		<?= $this->text ?>
	</div>

this is clearly wrong!

2
  • what is exactly "position" ? A PHP array ? Commented Feb 25, 2019 at 12:30
  • 1
    Print out $this->position and see if it holds left or right. Also, don't add two class=..., add it to the already existing class attribute. Also remember that PHP is serverside so if you want to change that value via a <select> you'd first need to submit the changes or use Javascript to attach that class onChange Commented Feb 25, 2019 at 12:46

2 Answers 2

1

Move your PHP condition into the existing class= instead of trying to create another instance of class= which is wrong.

<div class="floating_text <?php echo ($this->position == 'left') ? 'left' : '' ?>">
        <?= $this->text ?>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

@kerbholz thanks for the tip!

<div class="floating_text <?php if ($this->position === 'left') echo left ?>">

or I could have also just done this:

	<div class="floating_text <?php echo $this->position ?>">

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.