- Posts: 35
COMMUNITY FORUM
K2 different Image and Attatchment Path
- Alex
-
Topic Author
- Offline
- Junior Member
I got one problem, which i dont know, how i can solve it.Krikor wrote: You 're welcome Alex.
I show all extra field in a list. Befor this list ist the Text: "K2_ADDITIONAL_INFO"
This "K2_ADDITIONAL_INFO" of course shows only, if there are some extra fields, at this item.
Now i made one extra field, my attatchment. So the "K2_ADDITIONAL_INFO" text shows always, since this is an extra field, even i got no extra fields to show. So the first line of the code wont do the job is sould in my case.
How can i change the following lines?
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
...
My extra fields for attatchments have id: 25,26,27 and 18.
Thank you for any ideas.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The K2_ADDITIONAL_INFO indicates that there is a missing language string, you can either reinstall the language pack or use J!'s language overrides.
docs.joomla.org/J3.x:Language_Overrides_in_Joomla
Alternatively you can remove the header from your overrides.
Please Log in or Create an account to join the conversation.
- Alex
-
Topic Author
- Offline
- Junior Member
- Posts: 35
Krikor wrote: Is the block bellow the header empty?
The K2_ADDITIONAL_INFO indicates that there is a missing language string, you can either reinstall the language pack or use J!'s language overrides.
docs.joomla.org/J3.x:Language_Overrides_in_Joomla
Alternatively you can remove the header from your overrides.
Sorry, i didnt discribe my problem good enough. The language overrride works fine, the "K2_ADDITIONAL_INFO " is just a placeholder.
I ment, i use 4 extra fields as attatchment (u told me how to), these 4 extra fields sould not appear in my extra field list of course.
Thats why i hard coded them out there, but "count($this->item->extra_fields)" in my code above of course counts these 4 fields.
So the placeholder "K2_ADDITIONAL_INFO " from the languagefile gets diplayed, even if there are no other extra fields (besides ma 4 attatchments, who get not displayed in extra field part), in this item.
I gues i have to change the if query of extra fields, so that is detects, that there are no other extra fields in my item _besides_ my 4 extra fields i use for attatchemnts. These 4 fields, have the id 25,26,17 and 28.
It should look like:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields(**but_do_not_count_id25,26,27,28**))): ?>
But i have no idea, who the syntax for this can be.
Someone got an idea?
Please Log in or Create an account to join the conversation.
- Alex
-
Topic Author
- Offline
- Junior Member
- Posts: 35
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
That ist becomes false, if there is no item extra field expect my attatchmend extra field (id=25)?
Noone got an idea?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
a) Remove the extrafields loop altogether and render each extrafield individually.
b) Inside the loop, check the extrafield's id and if the id matches (if/else statement, in_array() etc) do nothing.
Please Log in or Create an account to join the conversation.
- Alex
-
Topic Author
- Offline
- Junior Member
- Posts: 35
Hi Krikor,Krikor wrote: b) Inside the loop, check the extrafield's id and if the id matches (if/else statement, in_array() etc) do nothing.
this is what i already do, inside the foreach loop i check "if($extraField->id != 25)", so that it doesnt show in the extra field list. Works so far. But the "<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>" line is before the loop, so it gets displayed, even there are no real extra fields.
I have done:
<?php if($this->item->extra_fields->id != 25): ?>
befor this headerline, but it doesnt work somehow, the headerline still gets displayed.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Since you are working with only a handful of fields, you need to drop the default check and either use the alias to check if the OTHER fields -https://github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L105-L109 - hold value or use the position in the extrafields array - $this->item->extra_fields[ARRAY_POSITION]->value
Remember, you need to manually check if the other fields hold any value.
Please Log in or Create an account to join the conversation.
- Alex
-
Topic Author
- Offline
- Junior Member
- Posts: 35
To default check each field manually isnt good solution for me, because, when i add a field, i do not want to adjust the item.php each time.
I did also a loop around the header line, like this:
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if(($extraField->value != '') && ($extraField->id != 25) ): ?>
<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
<?php break; ?>
<?php endif; ?>
<?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
This is a more versatile solution indeed.
Please Log in or Create an account to join the conversation.