Keyword

Query extrafields if statement

  • Marc
  • Marc's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago #57645 by Marc
Query extrafields if statement was created by Marc
I'm using this at the top of my item.php which I got from

community.getk2.org/forum/topics/top-tip-for-templating-k2s

//setup new array

$exFields = array();

//loop thru extrafields and build collection of key and values

foreach ($this->item->extra_fields as $key=>$extraField):
$exFields[$extraField->name] = $extraField->value;

endforeach;

I'm trying to query the name to see if it equals a value and if it does publish a different date, heres the code I'm trying

<?php if $extraField->name =["Closing date"]; ?>
{
<span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span>
<span class="catItemExtraFieldsValue"><?php echo $this->item->publish_down, JText::_('K2_DATE_FORMAT_LC2')); ?></span>
}
else
{
<span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span>
<span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
}
<?php endif; ?>

Can't get it to work, if someone who knows php could tell me what I'm doing wrong would greatly appreciate it.

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

More
12 years 11 months ago #57646 by william white
Replied by william white on topic Re: Query extrafields if statement
Remove the square brackets from around name

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

  • Marc
  • Marc's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago #57647 by Marc
Replied by Marc on topic Re: Query extrafields if statement
Removed square bracket, didn't work, pretty sure it is the syntax of the actual IF statement.

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

More
12 years 11 months ago #57648 by william white
Replied by william white on topic Re: Query extrafields if statement
What versions are you working with, K2? Joomla?
Please attach the php file you are working with. Are you working in an override structure?
Are you getting an error message?

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

  • Marc
  • Marc's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago #57649 by Marc
Replied by Marc on topic Re: Query extrafields if statement
Joomla 1.5.23. Setup as using a custom template, works fine without the if statement. Current K2 as well. php file attached I hope.

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

  • Marc
  • Marc's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago #57650 by Marc
Replied by Marc on topic Re: Query extrafields if statement
Sorry, now uploaded as zip.
Attachments:

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

More
12 years 11 months ago #57651 by william white
Replied by william white on topic Re: Query extrafields if statement
I see your code but do not understand why you are not testing the value of the extra field.
What you are trying to do seems to me to be much different than the example you started with.
Do you have a link to the live site?
Maby someone else will "get" what your trying to do

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

  • Marc
  • Marc's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago - 12 years 11 months ago #57652 by Marc
Replied by Marc on topic Re: Query extrafields if statement
Link to page I'm testing it on is

www.onlinecompetitions.com/index.php/test-category-3.html

I'm testing the field name for "Closing Date" as I have an extra field called Closing Date. I want the closing date to show the finish publishing date, which is the publish_down.

Testing everything else, the problem seems to be the if statement syntax.

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

  • Marc
  • Marc's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago #57653 by Marc
Replied by Marc on topic Re: Query extrafields if statement
Got it working, there was an extra ) at the end of one of the statements..... oh well 8 hours learning stuff isn't that bad I suppose.

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


Powered by Kunena Forum