- Posts: 22
COMMUNITY FORUM
Adding extra fields to existing items
- Big Ron
-
Topic Author
- Offline
- Junior Member
Less
More
10 years 2 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
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 2 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.
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.
Please Log in or Create an account to join the conversation.
- Big Ron
-
Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
10 years 2 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.
<!-- 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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 2 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..)
and you use var_dump() to show the actual value of the extrafield (could be NULL etc..)
Please Log in or Create an account to join the conversation.
- Big Ron
-
Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
10 years 2 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.
I then tried:
<?php var_dump($extraField); ?>
Which outputted nothing also.
Please Log in or Create an account to join the conversation.
- Big Ron
-
Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
10 years 2 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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 2 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?
Please Log in or Create an account to join the conversation.
- Big Ron
-
Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
10 years 2 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
<!-- 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
-
Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
10 years 2 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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 2 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:
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}]
Please Log in or Create an account to join the conversation.
- Luke Johnson
-
- Offline
- New Member
Less
More
- Posts: 1
10 years 2 months ago #141070
by Luke Johnson
Replied by Luke Johnson on topic Adding extra fields to existing items
I'm not sure if this is completely related --
I have added some extra fields to an existing item using the Joomla CMS, but am having trouble figuring out where to make these values appear on the frontend. Where is the PHP/HTML template that controls the frontend page? Here is an example product page on the website I'm supporting: www.exmweb.com/index.php?option=com_k2&view=item&id=147:es-standard-door&Itemid=533&lang=en
(I'm sorry if this is an ignorant question -- I don't usually work in Joomla.)
I have added some extra fields to an existing item using the Joomla CMS, but am having trouble figuring out where to make these values appear on the frontend. Where is the PHP/HTML template that controls the frontend page? Here is an example product page on the website I'm supporting: www.exmweb.com/index.php?option=com_k2&view=item&id=147:es-standard-door&Itemid=533&lang=en
(I'm sorry if this is an ignorant question -- I don't usually work in Joomla.)
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 2 months ago #141095
by Krikor Boghossian
Replied by Krikor Boghossian on topic Adding extra fields to existing items
This link ->
www.exmweb.com/index.php?option=com_k2&view=item&id=147:es-standard-door&Itemid=533&lang=en&template=system
uses the default template shows the extrafields. This means that you need to download K2 and compare the default item.php's code to your overrides. The code is well commented so you won't have issue locating the extra fields block.
In order to locate the files you need to edit you need to read this post getk2.org/documentation/tutorials/174
www.exmweb.com/index.php?option=com_k2&view=item&id=147:es-standard-door&Itemid=533&lang=en&template=system
uses the default template shows the extrafields. This means that you need to download K2 and compare the default item.php's code to your overrides. The code is well commented so you won't have issue locating the extra fields block.
In order to locate the files you need to edit you need to read this post getk2.org/documentation/tutorials/174
Please Log in or Create an account to join the conversation.