- Posts: 2
COMMUNITY FORUM
Show extra field name within generic template
- Richard Bell
-
Topic Author
- Offline
- New Member
Less
More
15 years 7 months ago #73114
by Richard Bell
Show extra field name within generic template was created by Richard Bell
Within generic.php I can see that extra_fields that are returned by performing a print_r of $this->items. My problem is that this doens't include the name of the extra field only id & value.
How would I go about adding name to the returned list of values? At the moment I see the following;
[extra_fields] => [{"id":"8","value":"9cm, 16cm, 23cm, 30cm"},{"id":"11","value":"test"}]
How would I go about adding name to the returned list of values? At the moment I see the following;
[extra_fields] => [{"id":"8","value":"9cm, 16cm, 23cm, 30cm"},{"id":"11","value":"test"}]
Please Log in or Create an account to join the conversation.
- David Mead
-
- Offline
- New Member
Less
More
- Posts: 4
15 years 7 months ago #73115
by David Mead
Replied by David Mead on topic Show extra field name within generic template
Unfortunately I don't have an answer for you but a question instead. I was hoping you could enlighten me as to how you were able to add in the extra fields to the generic item view (with more detail than you have above). I've been trying to augment the com_k2\templates\generic.php with some code from category-item.php, but no luck yet. Ultimately, I would like the generic view match the category list view so I also need to be able to show the Print and Share buttons as well. Any help would be greatly appreciated. Thanks!
Please Log in or Create an account to join the conversation.
- Richard Bell
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 2
15 years 7 months ago #73116
by Richard Bell
Replied by Richard Bell on topic Show extra field name within generic template
I would say that this isn't an ideal fix for adding in extra fields to the generic view but this is how I acheived it;
If you print_r($item) within the item loop you will see all that is avaliable to use within your template it is just accessing what you want to use. The extra fields for example are returned using JSON so they need decoding;
$extras can then be manipulated to return either its value or its ID!
If you print_r($item) within the item loop you will see all that is avaliable to use within your template it is just accessing what you want to use. The extra fields for example are returned using JSON so they need decoding;
$extras can then be manipulated to return either its value or its ID!
Please Log in or Create an account to join the conversation.
- David Mead
-
- Offline
- New Member
Less
More
- Posts: 4
15 years 7 months ago #73117
by David Mead
Replied by David Mead on topic Show extra field name within generic template
Thanks Richard, I'll see what I can do.
Richard Bell said:I would say that this isn't an ideal fix for adding in extra fields to the generic view but this is how I acheived it;
If you print_r($item) within the item loop you will see all that is avaliable to use within your template it is just accessing what you want to use. The extra fields for example are returned using JSON so they need decoding;
$extras can then be manipulated to return either its value or its ID!
Richard Bell said:I would say that this isn't an ideal fix for adding in extra fields to the generic view but this is how I acheived it;
If you print_r($item) within the item loop you will see all that is avaliable to use within your template it is just accessing what you want to use. The extra fields for example are returned using JSON so they need decoding;
$extras can then be manipulated to return either its value or its ID!
Please Log in or Create an account to join the conversation.
- Peter Haupt
-
- Offline
- New Member
Less
More
- Posts: 17
15 years 5 months ago #73118
by Peter Haupt
Replied by Peter Haupt on topic Show extra field name within generic template
How can decode the var $extrafield?
My code at the moment is:
$extraField = $item->extra_fields;
echo $extraField;
result is:
[{"id":"1","value":"Termin1\r\nTermin2\r\nTermin3"},{"id":"2","value":"\u20ac 2.000,-"},{"id":"3","value":"3"},{"id":"4","value":"1"},{"id":"5","value":"N\/A"},{"id":"6","value":"abgesagt"}]
What I would need is only the value of ID:5 or 6!
My code at the moment is:
$extraField = $item->extra_fields;
echo $extraField;
result is:
[{"id":"1","value":"Termin1\r\nTermin2\r\nTermin3"},{"id":"2","value":"\u20ac 2.000,-"},{"id":"3","value":"3"},{"id":"4","value":"1"},{"id":"5","value":"N\/A"},{"id":"6","value":"abgesagt"}]
What I would need is only the value of ID:5 or 6!
Please Log in or Create an account to join the conversation.
- Dragan Todorovic
-
- Offline
- New Member
Less
More
- Posts: 14
14 years 4 months ago #73119
by Dragan Todorovic
Replied by Dragan Todorovic on topic Show extra field name within generic template
it is json string
<?php
$custom = json_decode($item->extra_fields);
$first_xfield = $custom[0]->value[1];
?>
<?php echo $first_xfield ?>
ro find all
do
print_r ( $custom);
<?php
$custom = json_decode($item->extra_fields);
$first_xfield = $custom[0]->value[1];
?>
<?php echo $first_xfield ?>
ro find all
do
print_r ( $custom);
Please Log in or Create an account to join the conversation.
- Alan Sparkes
-
- Offline
- Premium Member
Less
More
- Posts: 118
14 years 4 months ago #73120
by Alan Sparkes
Replied by Alan Sparkes on topic Show extra field name within generic template
What about when extrafield is a select list?
Dragan Todorovic said:
it is json string
<?php
$custom = json_decode($item->extra_fields);
$first_xfield = $custom[0]->value[1];
?>
<?php echo $first_xfield ?>
ro find all
do
print_r ( $custom);
Dragan Todorovic said:
it is json string
<?php
$custom = json_decode($item->extra_fields);
$first_xfield = $custom[0]->value[1];
?>
<?php echo $first_xfield ?>
ro find all
do
print_r ( $custom);
Please Log in or Create an account to join the conversation.
- Dragan Todorovic
-
- Offline
- New Member
Less
More
- Posts: 14
14 years 4 months ago #73121
by Dragan Todorovic
Replied by Dragan Todorovic on topic Show extra field name within generic template
did not test ,
use print_r and output here if you have trouble , il try to help Alan Sparkes said:
What about when extrafield is a select list?
Dragan Todorovic said:
it is json string
<?php
$custom = json_decode($item->extra_fields);
$first_xfield = $custom[0]->value[1];
?>
<?php echo $first_xfield ?>
ro find all
do
print_r ( $custom);
use print_r and output here if you have trouble , il try to help Alan Sparkes said:
What about when extrafield is a select list?
Dragan Todorovic said:
it is json string
<?php
$custom = json_decode($item->extra_fields);
$first_xfield = $custom[0]->value[1];
?>
<?php echo $first_xfield ?>
ro find all
do
print_r ( $custom);
Please Log in or Create an account to join the conversation.