Keyword

K2 different Image and Attatchment Path

  • Alex
  • Alex's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 6 months ago - 8 years 6 months ago #152486 by Alex
Replied by Alex on topic K2 different Image and Attatchment Path

Krikor wrote: You 're welcome Alex.

I got one problem, which i dont know, how i can solve it.
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.
Last edit: 8 years 6 months ago by Alex.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 6 months ago #152501 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 different Image and Attatchment Path
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.

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

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

  • Alex
  • Alex's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 6 months ago - 8 years 6 months ago #152506 by Alex
Replied by Alex on topic K2 different Image and Attatchment Path

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?
Last edit: 8 years 6 months ago by Alex.

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

  • Alex
  • Alex's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 5 months ago - 8 years 5 months ago #152870 by Alex
Replied by Alex on topic K2 different Image and Attatchment Path
In other words, how can i change in item.php the extra field line:
<?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?
Last edit: 8 years 5 months ago by Alex.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 5 months ago #152921 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 different Image and Attatchment Path
There are two ways to approach this issue.

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.

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

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

  • Alex
  • Alex's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 5 months ago #152923 by Alex
Replied by Alex on topic K2 different Image and Attatchment Path

Krikor wrote: b) Inside the loop, check the extrafield's id and if the id matches (if/else statement, in_array() etc) do nothing.

Hi Krikor,
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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 5 months ago #152978 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 different Image and Attatchment Path
Outside the loop $this->item->extra_fields->id != 25 will not work.
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.

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

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

  • Alex
  • Alex's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 5 months ago #153004 by Alex
Replied by Alex on topic K2 different Image and Attatchment Path
Okay got it working.
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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 5 months ago #153061 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 different Image and Attatchment Path
Kudos :)
This is a more versatile solution indeed.

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