Question

So basically I've installed K2 on a Joomla! based website and I have IntroText turned on for category views. There is a Master category, Master, of which all other categories are subcategories, which is how you have to apply IntroText to multiple categories because K2 is finicky - set all the options you want in the Master category and call them from the subcategories.

My particular problem is with losing HTML formatting in IntroText, so all blog posts would look like a brick of text (red lines denote where a paragraph should start, i.e. the <p> tag): Mein Probleim

It should look like the following: No problemo

I have tried changing pretty much every setting in the Category View option in the Master category to no avail, as the page the IntroText on is a K2 Category page. I have also tried turning ON HTML formatting (it is off by default) and then excluding the p and br tags from being removed, to no avail.

After some Googling, I couldn't find an answer, but I will admit there were one or two I didn't try (mainly modding the PHP files, I would have tried if the answer actually had some feedback). So, if anyone has any suggestions or ideas, let me know please, I would appreciate it. I can provide more details if needed, but for the time being the site is offline. If you would like some more clarification on the website set up I can oblige, but I believe I've added all relevant K2 details that I could.

EDIT: I have also tried commenting out these lines in /~siteDir~/public_html/modules/mod_articles_category/helper.phpto fix the issue, which also didn't work.

 $introtext = str_replace('<p>', ' ', $introtext); 
 $introtext = str_replace('</p>', ' ', $introtext); 
 $introtext = strip_tags($introtext, '<a><em><strong>');

EDIT2: I tried to just remove the whole _cleanIntrotext function and the call for it, $item->introtext = self::_cleanIntrotext($item->introtext);, but this also didn't work... which means something somewhere else is stripping the IntroText too?

Was it helpful?

Solution

In order to keep the initial formatting of the introtext inside the K2 content module you need to have your item creation options to using two editors. One for introtext and one for full text. You also need to have a specific amount of words in the introtext. This is imperative as you cannot limit the introtext word number afterwards in the module settings, as by default the word number strips out all html tags to avoid breaking the page code as the Introtext word limit field states: Introtext word limit Leave blank to diasble. If you enable this option, all html tags from the text will be cleaned up to make sure the html structure of the site does not brake.. Which imho is a good thing to leave it as is since you don't always know beforehand which <p> or other tag will be left open. I did this and it worked for me; the module kept all the initial formatting. So in conclusion in order to keep the formatting intact leave the Introtext word limit of the module blank and store separately the introtext and the fulltext when creating articles. If you need more info tell me.

EDIT

The same applies to category listings. As I see in your website you have set a limit to introtext inside your category settings. So you should check which category -parent or child- has the limit set and remove it. Go to Components>K2>Categories Click to edit the category(-ies) that have the limit, it should be in Item view options in category listings>Introtext word limit if you hover over the field title you'll see the same warning tooltip about tag stripping that I mentioned before.

To set your item creation to use two editors go to Componets>K2>Parameters>Advanced>Use one editor window for introtext & fulltext set this to No. That way you'll have two separate editors for your item. However this is not obligatory and if you don't need that you can simply add a Read more break anywhere in your text by clicking the button under the editor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top