Keyword

Ability to Display Tags and Styles in Intro Text

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 4 months ago #128994 by Timothy Michel
Ability to Display Tags and Styles in Intro Text was created by Timothy Michel
I noticed that K2 strips all tags and styles from intro text. Will there be the ability in the future to allow some styles and tags to survive the stripping process?

Take a look here: www.jsandbox.org/evidence/videos/videos-by-others/content/161-confronting-nist.html

I want <a href="">, <p>, <strong>, <b>, <i> and the styles applied to these tags to survive the tags and styles stripping process.

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

More
10 years 4 months ago #128995 by Lefteris
Hi. K2 strips all tags only when word limit is applied. We do this in order to avoid breaking your site. If you disable the word limit you will see that HTML will be displayed normally.

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
More
10 years 4 months ago #128996 by Timothy Michel
Replied by Timothy Michel on topic Re: Ability to Display Tags and Styles in Intro Text
Word limit is kind of cool when you have many editors and you want to maintain a nice two column grid with each item having uniform height. Will this be added in future versions of k2 so that tag stripping and be turned on an off, while still setting the intro text word count in category item view?

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

More
10 years 3 months ago #128997 by Lefteris
It is not that simple. When PHP counts the words to strip the text it cannot understand which part is HTML code and which is the actual text. This may result to incomplete HTML tags. Newer versions of Joomla! include a function for this but we have not tested it yet. You can try it using the following code:
<?php echo JHTML::_('string.truncate', ($this->item->introtext),20); ?>

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
More
10 years 3 months ago - 10 years 3 months ago #128998 by Timothy Michel
Replied by Timothy Michel on topic Re: Ability to Display Tags and Styles in Intro Text
Thanks, which php file do I edit?
You mean replace:
<?php if($this->item->params->get('catItemIntroText')): ?>
<!-- Item introtext -->
<div class="catItemIntroText">
<?php echo $this->item->introtext; ?>
</div>
<?php endif; ?>

with:
<?php if($this->item->params->get('catItemIntroText')): ?>
<!-- Item introtext -->
<div class="catItemIntroText">
<?php echo JHTML::_('string.truncate', ($this->item->introtext),132); ?>
</div>
<?php endif; ?>

Remove the value from "Introtext word limit" in "Item view options in category listings" leave "Introtext" as "show" and remove the read-more link from the item.

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

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 3 months ago - 10 years 3 months ago #128999 by Timothy Michel
Replied by Timothy Michel on topic Re: Ability to Display Tags and Styles in Intro Text
This works pretty good, except that it is counting characters, not words so I had to use:

<?php echo JHTML::_('string.truncate', ($this->item->introtext),1024); ?>

But the Joomla routine counts tag characters as well as content characters so that an item with a lot anchors will have less characters displayed than an item with few anchors.

The way the count should be done is that when a '<' character is encountered, the count isn't incremented until after a '>' character is encountered. that way tags won't be counted. The problem arises when the counter routine encounters text like '20 < 100'. I suppose the way around that is to have specific character sequences look-ups like '<p' and '<a' and '<h1' and '<h2' etc. if these sequences are encountered, then the counter value for the loop would have to be increased by the amount of the characters contained in those sequences.

I decided to set 'Introtext HTML cleanup (tag strip)' to 'No" and judiciously place the read more link so that it displays the correct amount of characters. I will have to make the writers to carefully adjust the read-more link to get the right results. This produces the most pleasing results even if it consumes a bit of time to correctly position the read-more link.

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

  • Timothy Michel
  • Timothy Michel's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 3 months ago #129000 by Timothy Michel
Replied by Timothy Michel on topic Re: Ability to Display Tags and Styles in Intro Text
I kept playing with this and this is what I finally settled on.

In "Item view options in category listings" I set "Introtext" to "Show" and "Introtext word limit" to 150. In "Item view options" I set "Introtext" to "Hide" and "Fulltext" to "Show." This has K2 stripping the Intro Text of all tags. The problem I had with this is that K2 is counting words and not characters which means that the word count is the same for each Item Intro, but the character count isn't. To remedy this I replaced <?php echo $this->item->introtext); ?> with <?php echo JHTML::_('string.truncate', ($this->item->introtext),640); ?> in category_item.php which counts out 640 characters from the stripped intro text and display that through the echo command. 640 characters is less than 150 words so an ellipsis get appended at the end and everything looks good. Now I have to have dedicating intro text at the beginning of the articles, and I still have to insert a read-more link after the intro text, but I get category views for items that follow a uniform grid pattern, though all tags are stripped, but I get the full text view of the items with all formatting applied including the Intro text if I duplicate that above and below the read-more link.

You can see the results here

By adding a dozen @media queries in K2.css I was able to get the item intro containers grid to remain uniform regardless of viewport resolution..

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

More
10 years 3 months ago #129001 by Lefteris
I ma glad you found a workaround. I think that the best we can have is write a version of string.truncate to count words and not characters. Thank you for your great feedback.

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
More
10 years 3 months ago #129002 by Timothy Michel
Replied by Timothy Michel on topic Re: Ability to Display Tags and Styles in Intro Text
We could augment the Category Item interface to allow certain tags and require the user to input the scalar values of the styles associated with those certain tags as well as input the dimension of their container divs. Does get complicated, so the options would have to be limited. But allowing <p>, <h2>, <h3>, <h4>, <h5>, <h6>, <a>, <ol>, <ul> and asking for line-height and font-size and indents for these might be doable.

If tags were to be included, a rule would have to be enforced that no inline styles could be included as those would break the display of the content, and all dimensional properties assigned in css for those tags would have to be entered for each tag that would be permitted to survive the stripping process.

Counting characters has it's advantages though because words can be contain all sorts of numbers of characters. The idea is to arrive at a uniform amount of content every time.

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

  • GertJan van Schuppen
  • GertJan van Schuppen's Avatar
  • Offline
  • New Member
More
10 years 2 months ago #129003 by GertJan van Schuppen
Replied by GertJan van Schuppen on topic Re: Ability to Display Tags and Styles in Intro Text

Lefteris Kavadas wrote: It is not that simple. When PHP counts the words to strip the text it cannot understand which part is HTML code and which is the actual text. This may result to incomplete HTML tags. Newer versions of Joomla! include a function for this but we have not tested it yet. You can try it using the following code:

<?php echo JHTML::_('string.truncate', ($this->item->introtext),20); ?>


Hi,

I have used this PHP code and it is working good! have a look here: www.madonnafanclub.nl/nieuws/actueel

Only a litle problem > as you can see all articles have a READ MORE (Lees meer) button. That's OK. But just above the button there are 3 dots... I think these come because of the introtext limitations. Is it possible to NOT show those dots?

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


Powered by Kunena Forum