Forums / Cotonti / Support / I want to control {TAGS_RESULT_ROW_TAGS}

I want to control the output of {TAGS_RESULT_ROW_TAGS}

aiwass
#1 2016-05-07 10:45

Hi,

I want to control how {TAGS_RESULT_ROW_TAGS} is outputted from tags/tags.php.

What it currently is producing, standard with no modifications, is this this:

<a href="tags/batman">Batman</a>, <a href="tags/gumball-3000">Gumball 3000</a>, 

I want it to be more like this and something I can control/change when needed:

<a href="tags/batman" rel="tag"><span itemprop="keywords">Batman</span></a>, <a href="tags/gumball-3000" rel="tag"><span itemprop="keywords">Gumball 3000</span></a>, 

So the problem is that {TAGS_RESULT_ROW_TAGS} is something I want to control how it looks and behaves and there are other controllable bits listed in plugins/tags/inc/tags.resources.php but I can't seem to find the one that makes {TAGS_RESULT_ROW_TAGS} do as I want it too.

 

Help!

Take all that money that we spend on weapons and defences each year and instead spend it feeding and clothing and educating the poor of the world, which it would many times over, not one human being excluded, and we could explore space, together, both inner and outer, forever, in peace. - Bill Hicks

https://evlear.com
Macik
#2 2016-05-07 16:12

Unfortunly, there is no predefined method to extend `{TAGS_RESULT_ROW_TAGS}` generation process. As it not use resource strings as done for forum topic tags list with `tags_link_tag` resoure string.

In spite of that, we can use some tricks and try to do some customization. Let's see in `tags.php` file, line 239: 

if ($tag_i > 0) $tag_list .= ', ';
$tag_list .= cot_rc_link(cot_url('plug', array('e' => 'tags', 'a' => 'pages', 't' => str_replace(' ', '-', $tag_u), 'tl' => $tl)), htmlspecialchars($tag_t));
$tag_i++;

It's where acrual generation is done. This line goes within `foreach` loop.

`cot_rc_link` use predefined (built-in) string resource, so we can not alter it. Only we have it's a generated comma separated list of links...
So now there is only one way to customize it — to alter already genererated string with a callback function.
We can do it with own custom function, placed in `yourthemename.php` or `system/functions.custom.php`. And call it from our template:

{TAGS_RESULT_ROW_TAGS|my_tagslist_customization($this)} 

The function can look like this (I'm writing it without tests so fix it for your needs):

function my_tagslist_customization($tagslist)
{
  $items = preg_split('/\s*,\s*/', $tagslist);
  foreach ($items as &$item)
  {
     $item = preg_replace('>(\w+)</a>',' rel="tag"><span itemprops="keywords">$1</span></a>', $item);
  }
  return implode(',', $items);
}

Or you can do this right in template, example:

{TAGS_RESULT_ROW_TAGS|preg_replace('>(\w+?)</a>',' rel="taglink"><span itemprops="keywords">$1</span></a>',$this)}

 

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
aiwass
#3 2016-05-07 17:11

This became the result:

<a href="tags/waifs-and-strays">Waifs And  rel="taglink"&gt;<span itemprops="keywords">Strays</span></a>

after using :

{TAGS_RESULT_ROW_TAGS|preg_replace('>(\w+?)</a>',' rel="taglink"><span itemprops="keywords">$1</span></a>',$this)}

 

Im not a programmer, so I'm not so good at this. Also tags that are 2 words or more will not function

either since the "$1" seems to only pick the last word in a 2 word phrase, as you can see in the above result.

Added 2 days later:

This string of code works, sort off not 100%:

{TAGS_RESULT_ROW_TAGS|preg_replace('>(\w*[a-z-0-9_])</a>',' <a href="tags/$1" rel="tag"><span itemprop="keywords">$1</span',$this)} 

Sine the output looks like this

<a href="tags/tesla"> </a>
<a href="tags/Tesla" rel="tag"><span itemprop="keywords">Tesla</span>
</a>

As you can see it produces the link 2 times, one without the tag in visible text form and one with all the added things but it also makes the tag Uppercase for some unknown reason. The trailing > after </span is deleted becuase it produces an extra > after the </a>.

Either I'm a complete idiot or there is a but in how the output is being made for the {TAGS_RESULT_ROW_TAGS} since its seeminly impossible to control it in order to have the output that one wants. Mainly because someone decided that this is not something that one should control, which was a really bad choice, since one can control all the other things related to Tags.

I desperatly need a solution for this.

Take all that money that we spend on weapons and defences each year and instead spend it feeding and clothing and educating the poor of the world, which it would many times over, not one human being excluded, and we could explore space, together, both inner and outer, forever, in peace. - Bill Hicks

https://evlear.com
This post was edited by aiwass (2016-05-10 00:03, 7 years ago)
Macik
#4 2016-05-18 17:38

My code is a sample, not a complete solutuion. I use `\w+` metacharacter only for example, it covers only  character from a-z, A-Z, 0-9 range and includes the _ (underscore) character. It not cover cases with several words (with spaces between) or special symbols (like unicode). So RegExp needs to be updated to cover your cases. 

The proper way is to alter code to use Resource Strings API for this tag generation. You can post a request for it by submiting an issue to Cotonti project on GitHub.

 

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F