Keyword

Adding extra fields to existing items

  • Big Ron
  • Big Ron's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 9 months ago #140424 by Big Ron
Adding extra fields to existing items was created by Big Ron
Hi,

I have added some extra fields with a default value to existing items in a category.

The problem I am experiencing is that the default value is not being outputted unless I edit that item. There are over 300 items so not very realistic!

Any help would be appreciated.

Thanks

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 9 months ago #140467 by Krikor Boghossian
Replied by Krikor Boghossian on topic Adding extra fields to existing items
Hello Ron,
Unfortunately since the extrafield was created after the item it is stored as blank.

You can perform a check in your overrides and display a value if that field is empty.

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

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

  • Big Ron
  • Big Ron's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 9 months ago #140540 by Big Ron
Replied by Big Ron on topic Adding extra fields to existing items
Thanks. I am trying the following:

<!-- Item extra fields -->
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>

<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != ''): ?>

<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>

<?php else: ?>

<span class="itemExtraFieldsValue">Second version 1997</span>

<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>

So IF extra value field NOT empty show value ELSE show custom HTML.

The problem is the ELSE statement doesnt seem to be working even thought the items have an empty extra field.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 9 months ago #140565 by Krikor Boghossian
Replied by Krikor Boghossian on topic Adding extra fields to existing items
Try with !==
and you use var_dump() to show the actual value of the extrafield (could be NULL etc..)

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

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

  • Big Ron
  • Big Ron's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 9 months ago #140570 by Big Ron
Replied by Big Ron on topic Adding extra fields to existing items
I tried using !== and also checking for NULL. No joy on the ELSE part of the statement.

I then tried:

<?php var_dump($extraField); ?>

Which outputted nothing also.

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

  • Big Ron
  • Big Ron's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 9 months ago #140573 by Big Ron
Replied by Big Ron on topic Adding extra fields to existing items
Although <?php var_dump($extraField); ?> does work for items that have some content in the extra field.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 9 months ago #140574 by Krikor Boghossian
Replied by Krikor Boghossian on topic Adding extra fields to existing items
Can I have the latest example of your code, and that particular field's alias?

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

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

  • Big Ron
  • Big Ron's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 9 months ago #140575 by Big Ron
Replied by Big Ron on topic Adding extra fields to existing items
I have reverted the code back to:

<!-- Item extra fields -->
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>

<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != ''): ?>

<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>

<?php else: ?>

<span class="itemExtraFieldsValue">Second version 1997</span>

<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>



The alias is:

Alternativelabel

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

  • Big Ron
  • Big Ron's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 9 months ago #140576 by Big Ron
Replied by Big Ron on topic Adding extra fields to existing items
Looking in the database and those fields have []

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 9 months ago #140651 by Krikor Boghossian
Replied by Krikor Boghossian on topic Adding extra fields to existing items
Ok, something went wrong then if the value cell in the xx_k2_extra_fields table is empty.

Try adding a new field and check the db.

An example value be:
[{"name":null,"value":"","editor":null,"rows":"","cols":"","target":null,"alias":"map","required":0,"showNull":0}]

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

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


Powered by Kunena Forum