COMMUNITY FORUM
After Update to K2 2.9 Extra Fields Don't Work At All
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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.
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
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
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
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
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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. :)
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
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
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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.
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
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:
Which means I need to quiz our web host.[Fri Oct 12 19:31:50 2018] [warn] [client 174.81.12.11] mod_fcgid: error reading data from FastCGI server
and
Which means I have to look at my index.php file.Fri Oct 12 19:31:50 2018] [error] [client 174.81.12.11] Premature end of script headers: index.php
Thanks, Tim
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
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
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
I am also having a conversation with Joomla over the new CSS core properties. They are proudly advertising that Joomla 4.0 will sport Twitter Bootstrap 4.0 and I argue that now that we have CSS Grids and Flexbox elements, that Bootstrap really isn't all that important any more.for layout.
I have read other arguments that CSS Grids is a core technology and that Bootstrap is third party, Twitter, and that it is always better to go with core when core supports everything we need to do.
I was wondering how you felt about that. That little HTML file I attached was only 11K in size, and yet it adapts nicely to iPhones, tablets and desktops. I could never do that with Bootstrap in 11K.
Thanks, Tim
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
I also think that the plan for BootStrap is to eventually support CSS Grids for layout/structure while offering a fallback for older browsers or browser that don't fully support the Grid & Flex specs yet.
Additionally, if I were to choose JS libs to be included from 3rd parties, I would definitely use jQuery 3.x, BootStrap v4 (they are not related to Twitter anymore BTW) and perhaps Vue.js as essential libraries to make developers' and integrators' lives easier. Otherwise we'll end up with dozens of libraries (even same but with different versions) being loaded into the Joomla frontend or backend. It's not a bad thing utilising proven/successful 3rd party projects in Joomla.
And I wouldn't worry on performance. As server's move to HTTP/2, it doesn't matter if you have 100 CSS/JS scripts. The protocol works differently to HTTP 1.1 and the browser bundles these files and downloads them much more intelligently and more efficient. Not to mention a few extra KBs won't hurt anyone...
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Programming is a lot of work
After poking around the web, I came across this statement that suggests that CSS Grids and Bootstrap 4.0 will live happily together in Joomla 4:
See: The Future of Joomla is CSS Grid, Not Bootstrap 4Joomla 4 is currently in development. It may be many months before Joomla 4 is released, but we're already working on comparability for Joomlashack templates.
One of the most important changes in Joomla 4 is the upgrade from Bootstrap 2 to Bootstrap 4. However, one thing we've discovered is that Joomla 4 will not rely exclusively on Bootstrap.
Joomla 4 will also rely on CSS Grid Layout, a CSS method that is revolutionizing the frontend web design industry.
Bootstrap 4 and CSS Grid Layout will be the tools used for frontend design in Joomla 4. Joomla will rely on Bootstrap 4 for the user interface, and CSS Grid for the frontend layouts. The Joomla team are making this change because they believe that CSS Grid will be more future-proof. In Joomla 3, they were locked into an old version of Bootstrap. The hope is that this new approach will avoid similar problems with Joomla 4.
It would seem, to me, that this is a reasonable approach, what do you think, considering what you said about the future of Bootstrap?
Thanks, Tim
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.