Keyword

After Update to K2 2.9 Extra Fields Don't Work At All

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
  • Programming is a lot of work
More
6 years 1 month ago #169427 by Timothy Michel
I have Extra Fields, Title Second Line, Subtitle 1 and Subtitle 2.

Before update to K2 2.9 everything working without issue. Now none of the Subtitles nor the Title Second
Line (use that to break a title a into two parts when normal wrapping causes the title to break in an unattractive place), appear in the full articles.

Is there something I need to do to make these visible again.

Yes I just read the discussion about images, but that doesn't apply here because there is no path involved with plain text.

Thanks, Tim

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

More
6 years 1 month ago #169434 by JoomlaWorks
There is no change related to extra fields in the frontend code that renders the output.

To make sure it's not an override issue, simply rename your /html/com_k2 folder to /html/_com_k2 and check your site. Do the same if the error occurs with modules for which you have overrides too.

Let me know.

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

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

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
  • Programming is a lot of work
More
6 years 1 month ago #169577 by Timothy Michel
Replied by Timothy Michel on topic After Update to K2 2.9 Extra Fields Don't Work At All
Thanks Fotis, I know you guys must be really busy fielding all the questions that arose from the rollout of 2.9

I overrode the behavior of several files in K2 and overrode them correctly, but it appears that I may have altered item.php without overriding it. Looks like it was my lazy programming practice that is at issue here.

I believe the file responsible for displaying the ExtraFields is item.php located in components/com_k2/views/item/tmpl, is that correct?

If so I don't see it in my override folder, so I must have altered the PHP, and HTML without first copying that file to my-template/html/com_k2/item.

The Extra Field info is being displayed in the Additional Information section at the bottom of the article. I must have altered item.php a long time ago to check for the names of the particular Extrafields I created, and if found, display them under the main title. I called them titleRowTwo, subtitleOne and subtitleTwo, and each gets displayed slightly differently.

For anyone else reading this. This is why it is strongly recommended that for any file, we wish to alter, it needs to be placed in the directory TEMPLATE_NAME/html/EXTENSION_NAME/VIEW_NAME/FILE_NAME.php, and that version of the file is the one we alter. That way we don't end up having our site broken on update as just happened to me.

Thanks, Tim

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

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
  • Programming is a lot of work
More
6 years 1 month ago - 6 years 1 month ago #169578 by Timothy Michel
Replied by Timothy Michel on topic After Update to K2 2.9 Extra Fields Don't Work At All
I changed and added the following in item.php

Below the Title section I added:
<h2 class="itemTitle">
 <?php if(isset($this->item->editLink)): ?>
  <!-- Item edit link -->
  <span class="itemEditLink">
   <a data-k2-modal="edit" href="<?php echo $this->item->editLink; ?>"><?php echo JText::_('K2_EDIT_ITEM'); ?></a>
  </span>
 <?php endif; ?>

 <?php echo $this->item->title; ?>

 <?php if($this->item->params->get('itemFeaturedNotice') && $this->item->featured): ?>
  <!-- Featured flag -->
   <span><sup>	<?php echo JText::_('K2_FEATURED'); ?></sup></span>
 <?php endif; ?>
</h2>
<?php endif; ?>
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
 <!-- Item article Title Row 2 extra field -->
 <?php if(isset($this->item->extraFields->titleRowTwo->value)): ?>	  	
  <h2 class="itemTitleRow2"><?php echo $this->item->extraFields->titleRowTwo->value; ?></h2>
 <?php endif; ?>
 <!-- Item article SubTitle 1 extra field -->
 <?php if(isset($this->item->extraFields->subtitleOne->value)): ?>
  <h3 class="itemSubTitle1"><?php echo $this->item->extraFields->subtitleOne->value; ?></h3>
 <?php endif; ?>			
 <!-- Item article SubTitle 2 extra field -->
 <?php if(isset($this->item->extraFields->subtitleTwo->value)): ?>	  	
  <h4 class="itemSubTitle2"><?php echo $this->item->extraFields->subtitleTwo->value; ?></h4>
 <?php endif; ?>
<?php endif; ?>

And I added a test in the Extra Fields section:
<?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>
 <?php if($extraField->value != '' && $extraField->name != 'Title Row 2' && $extraField->name != 'Subtitle 1' && $extraField->name != 'Subtitle 2'): ?>
  <ul>
   <?php foreach ($this->item->extra_fields as $key => $extraField): ?>
    <?php if($extraField->value != ''): ?>
     <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?> alias<?php echo ucfirst($extraField->alias); ?>">
			<?php if($extraField->type == 'header'): ?>
       <h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
      <?php else: ?>
       <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
       <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
      <?php endif; ?>
     </li>
    <?php endif; ?>
   <?php endforeach; ?>
  </ul>
  <div class="clr"></div>
<?php endif; ?>
</div>
<?php endif; ?>

And that solved my little problem

Thanks, Tim
Last edit: 6 years 1 month ago by Timothy Michel. Reason: Clean up the code

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

More
6 years 1 month ago #169584 by JoomlaWorks
All template overrides are in /components/com_k2/templates/.

All you need to know about override handling is here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

I've added some fixes for PHP 7.x in all template overrides just today so just grab and install K2 v2.9.1 dev from GitHub once more please. :)

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

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

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
  • Programming is a lot of work
More
6 years 1 month ago - 6 years 1 month ago #169589 by Timothy Michel
Replied by Timothy Michel on topic After Update to K2 2.9 Extra Fields Don't Work At All
I installed the latest release from github.com/getk2/k2 from "Clone or Download" which gives me k2-master.zip, and then updated the site to PHP 7.2.3, but I still get the error "0 - Using $this when not in object context" I assume that this is because PHP added stricter scope in the newer version. I switch back to PHP v. 7.0.28 and the site loads without error.

I have a Joomla site installed without K2 but using PHP v. 7.3.2 and have no problem with site loading.

If I am downloading the wrong version of K2, please direct me to the correct version.

I have the contents of /components/com_k2/templates/ copied into /templates/my_template/html/com_k2/. Somehow default/item.php got left behind for some reason.

Yes I agree we should all read: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates , this explains why K2 does things a little differently and actually enables different K2 templates for different content type, i.e., news, a knowledge base and a catalog of products. this is actually very powerful and allows us to create pages more appropriate to the specific content.

Joomla should have natively supported sub-templating. There is one Joomla extension I know about that provides this essential capability to Joomla, but still Joomla only supports one template per site. Consider the fact that I would want to lay out pages completely differently for mobile devices than I would for desktops, and that media queries only get me half the way there. This may be obviated by the combination of CSS Grids and @media queries, however; I have to create a Joomla template based exclusively on this new CSS display type and see what results I get. Even though CSS Grid does a lot, different section of the website would still want to be laid out different depending on content, which is why sub-templating is very useful.

Thanks, Tim
Last edit: 6 years 1 month ago by Timothy Michel.

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

More
6 years 1 month ago - 6 years 1 month ago #169592 by JoomlaWorks
Switch error reporting to maximum so you can see which part fails (and IF it's K2) as I'm working primarily on PHP 7.2 locally and have no issues at all.

As for sub-templating, JoomlaWorks was literally the first Joomla company to launch such features in its products. That's because we understand CM in CMS. What you want to do is probably called adaptive design/development and it's really not that hard.

In your template's index.php, this is what you need to have different subtemplates per device type:
<?php
// URLs with "?m" or "&m" render mobile pages - much like Google's Blogger does / "?force" or "&force" is used to force the desktop view
if(isset($_GET['m']) && !isset($_GET['force'])){
	include('index.mobile.inc.php');
} else {
	include('index.desktop.inc.php');
}

Then you need a system plugin (using the onAfterInitialise event) to set a PHP constant like define("SITE_VIEW", "mobile"); or define("SITE_VIEW", "desktop");:
		// Desktop or mobile
		if(isset($_GET['m']) && !isset($_GET['force'])){
			define("SITE_VIEW", "mobile");
		} else {
			define("SITE_VIEW", "desktop");
		}

And finally, in your html overrides under /html/com_k2/ you simply check for the value of SITE_VIEW to determine if the user visiting the site is using a mobile or desktop browser.

You would also need the JS redirect in your desktop sub-template, something like:
        <!-- Browser detect and redirect -->
        <script type="text/javascript">
            (function() {
                // Get URL query strings
                function getQS(v) {
                    var qs = window.location.search.substring(1);
                    var qsArray = qs.split("&");
                    for (i = 0; i < qsArray.length; i++) {
                        var qp = qsArray[i].split("=");
                        if (qp[0] == v) {
                            return true;
                        }
                    }
                }

                if (getQS('force')) {
                    document.getElementsByTagName('a').onclick = function(el) {
                        if (el.href.indexOf('?') > 0) {
                            el.href = el.href + '&force=1';
                        } else {
                            el.href = el.href + '?force=1';
                        }
                    }
                }

                if (getQS('m') === undefined) {
                    if (getQS('force')) return;
                    var curUrl = window.location.href;
                    var userAgent = navigator.userAgent || navigator.vendor || window.opera;
                    var getLastChar = curUrl.substr((curUrl.length) - 1);
                    if (((/Android/i).test(userAgent) && (/Mobile/i).test(userAgent)) || (/BlackBerry|iPhone|iPod|Opera Mini|IEMobile/i).test(userAgent)) {
                        if (curUrl.indexOf('?') > 0) {
                            window.location.replace(curUrl + '&m=1');
                        } else {
                            window.location.replace(curUrl + '?m=1');
                        }
                    }
                }
            })();
        </script>

The above makes sure to set ?m or &m and handle ?force or &force if there's a link to enforce the desktop view in your site.

I'm just giving you an idea on how to implement things here, it's not THE solution of course. But the above can work great with any type of caching, either Joomla-based caching or stricter server-side caching e.g. via Varnish or Nginx.

If you need more info, I could make a blog post with more details.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 6 years 1 month ago by JoomlaWorks.

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

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
  • Programming is a lot of work
More
6 years 1 month ago - 6 years 1 month ago #169692 by Timothy Michel
Replied by Timothy Michel on topic After Update to K2 2.9 Extra Fields Don't Work At All
Fotis, first of all, thank you so much for that detailed reply. Yes I want to develop adaptive templates. I plan to create a new Joomla template that nearly exclusively uses Flexbox CSS attributes and CSS Grids, and only use Bootstrap 2/3 classes where I have to. Even with CSS Grids, there is still a need for a specific mobile template. So the information you just provided is very very much appreciated.

I set error reporting to maximum as you suggested and then looked at error.log. I found a warning related to the K2/ACYMailing plugin and an error related to the template index.php file.

[Mon Sep 10 21:34:38 2018] [warn] [client 47.42.194.156] mod_fcgid: stderr: PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; plgAcymailingK2users has a deprecated constructor in /[path to plugins]/plugins/acymailing/k2users/k2users.php on line 8


As you can see this was 10 September, 2018 and may have already been corrected in v. 2.9. this may also have been written by ACYMailing.

I also found:

[Fri Oct 12 19:31:50 2018] [warn] [client 174.81.12.11] mod_fcgid: error reading data from FastCGI server

Which means I need to quiz our web host.

and

Fri Oct 12 19:31:50 2018] [error] [client 174.81.12.11] Premature end of script headers: index.php

Which means I have to look at my index.php file.

Thanks, Tim
Last edit: 6 years 1 month ago by Timothy Michel. Reason: Obfuscate path to administrator

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

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
  • Programming is a lot of work
More
6 years 1 month ago - 6 years 1 month ago #169697 by Timothy Michel
Replied by Timothy Michel on topic After Update to K2 2.9 Extra Fields Don't Work At All
About CSS Grids, Fotis, I think using CSS Grids makes Reactive Design unnecessary. See the attacked HTML file.

File Attachment:

File Name: grid-test.zip
File Size:3 KB


This took about two hours start to finish. I am amazed at how much this accomplishes with just 130 lines of CSS.

I added a demonstration of how DIVs can be moved around on the page using CSS Grids so the CSS ended up becoming 266 lines instead of 130.

Sub-templating is still very important, however, because even though CSS Grids makes designing a template orders of magnitude easier, not all pages are going to require the same set of DIVs, or the same logic,and that is where sub-templating comes in very handy.

Thanks, Tim
Attachments:
Last edit: 6 years 1 month ago by Timothy Michel. Reason: Update File

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

More
6 years 1 month ago #169748 by JoomlaWorks
This is actually an error in the AcyMailing plugin, it's not K2, nor can K2 control that. Send it over to the guys at Acyba and they should fix it.

Fotis / 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