MODX Community

Using Tagger and displaying the current tag selected

What I want is to display the current tag selected on the target resource. So the page would show “Current Category is [[+tag]]” or something.

I tried messing with TaggerGetCurrentTag , no luck there yet.

Any ideas?

I don’t use tagger, but if the tag is in a TV, you should be able to do this for the current page:

[[*tvName]]

Here is more what I mean.

One way around this might be to have something that gets the last word of the URI in the example above it would be /posts-by-tag/tag-2 So I just need to grab tag-2 , strip the hyphens and capitalize the first letter.

This is a horrible hack IMHO, but here is what I’m doing.

I made a snippet called getLastWordUrl

<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";   
echo basename($url);

Then dropped it into my content like as
[[getLastWordUrl:ucwords:replace=-== ]]

I’m replacing dashes with spaces and upper casing the first letter of each word.

Whatever works. :wink:

FYI, putting the conversions in the snippet will make it a whole lot faster. Chained output modifiers require parsing as an extra step.

<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";   
$url = basename($url);
$url = str_replace('-', ' ', $url);
return ucwords($url);

or as one line:

return ucwords(str_replace('-', ' ', basename("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")));