Keyword

Show if extra field contains a spesific value

  • neppers
  • neppers's Avatar Topic Author
  • Offline
  • Junior Member
More
6 years 8 months ago #162929 by neppers
How can I show some code in item.php if a extra field contains a spesific value?

<?php if(isset($this->item->extraFields->type->value CONTAINS CAR)): ?>
<!-- Item extra fields -->

<img src="/images/car.jpg">

<?php endif; ?>

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 8 months ago #162951 by Krikor Boghossian
Replied by Krikor Boghossian on topic Show if extra field contains a spesific value
You are halfway there. Since you are using multiple values you need to use this function php.net/manual/en/function.in-array.php in an extra if / else clause.
<?php $cars = array("Value1", "Value2", "Value3", "Value4");
if( isset($this->item->extraFields->EXTRAFIELDALIASHERE->value) && 
	in_array("CAR_VALUE", $this->item->extraFields->EXTRAFIELDALIASHERE->value) ): ?>

	Do Something
<?php endif; ?>

*this is untested

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • neppers
  • neppers's Avatar Topic Author
  • Offline
  • Junior Member
More
6 years 8 months ago #162956 by neppers
Replied by neppers on topic Show if extra field contains a spesific value
Thank you, but I am struggling to see the logic in this one. Can I ask you to explain Value1, Value2 etc and the CAR_VALUE?

Bear with me, and feel free to respond.

:-)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 8 months ago #162974 by Krikor Boghossian
Replied by Krikor Boghossian on topic Show if extra field contains a spesific value
Sorry the code should be:

in_array( $this->item->extraFields->EXTRAFIELDALIASHERE->value, $cars)

Value1, Value2 are simply the values you want to check.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • neppers
  • neppers's Avatar Topic Author
  • Offline
  • Junior Member
More
6 years 8 months ago #162988 by neppers
Replied by neppers on topic Show if extra field contains a spesific value
I still just get it to "Do nothing":

<?php $type = array("car");
if( isset($this->item->extraFields->Vaskeanvisning->value) &&
in_array( $this->item->extraFields->Vaskeanvisning->value, $type) ): ?>

Do Something
<?php else: ?>
Do Nothing

<?php endif; ?>

The extra field is a Multi-select list, and one of the selections contains the value car.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 8 months ago #162997 by Krikor Boghossian
Replied by Krikor Boghossian on topic Show if extra field contains a spesific value
What does this produce?
<?php var_dump($this->item->extraFields->Vaskeanvisning->value); ?>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • neppers
  • neppers's Avatar Topic Author
  • Offline
  • Junior Member
More
6 years 8 months ago #162998 by neppers
Replied by neppers on topic Show if extra field contains a spesific value
string(98) "Maskinvask 60 °C, Temperatur inntil 150 °C, Tåler kjemisk rensing, Tåler ikke klorbleking, car"

Please Log in or Create an account to join the conversation.

  • Ronny Van Der Borght
  • Ronny Van Der Borght's Avatar
  • Offline
  • Senior Member
More
6 years 7 months ago #163294 by Ronny Van Der Borght
Replied by Ronny Van Der Borght on topic Show if extra field contains a spesific value
How about:

<?php
$input = $this->item->extraFields->Vaskeanvisning->value;
$searchword = 'foo';
if (strpos($input, $searchword) !== false) {
echo 'foo has been found';
}
?>

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 7 months ago #163308 by Krikor Boghossian
Replied by Krikor Boghossian on topic Show if extra field contains a spesific value
strpos() php.net/manual/en/function.strpos.php will also do the trick :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • neppers
  • neppers's Avatar Topic Author
  • Offline
  • Junior Member
More
6 years 6 months ago #163948 by neppers
Replied by neppers on topic Show if extra field contains a spesific value
Thank you very much :-) This worked excellent.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum