Get Selected Tag on Tag block for Page List Filtering

Permalink
Hi,

I'm trying to highlight the selected tag when filtering a Page List block with a Tags block, similar to what happens with the Topic List block.

How can I retrieve what the selected tag is?
Should probably be straightforward but I'm not getting there..

Any help greatly appreciated.

Thanks

ESKEMA
 
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi ESKEMA,

In 5.7, you can make a custom template for the Tags block that gets the page request and extracts the tag segment from the URL.

- create the file tag_selected.php
application\blocks\tags\templates\tag_selected.php
- open tag_selected.php
- paste this code:
<?php defined('C5_EXECUTE') or die('Access Denied.');
use Concrete\Attribute\Select\OptionList;
// get the Concrete\Core\Http\Request object
$request = Request::getInstance();
// get the request path
$requestPath = $request->getPath();
// Example:
// /page_name/tag/pumpkin
// - "pumpkin" is the tag name
// look for /tag/ in the path
if (preg_match('/\/tag\//', $requestPath)) {
    // if "/tag/" is found, find the position
    // add 5 characters, so only the tag portion of the URL is selected
    $tagPosition = strpos($requestPath, '/tag/') + 5;
    // extract the portion of the URL that is the tag

The "Tag Selected" custom template would be applied to the Tags block on the same page as the filtered Page List.

The current selected tag (span) would have the class "ccm-block-tags-tag-selected".
ESKEMA replied on at Permalink Reply
ESKEMA
Sorry for the late reply!

Thank you very much. Works perfectly.
MrKDilkington replied on at Permalink Reply
MrKDilkington
@ESKEMA

This will be a default feature in the next version of concrete5 v8.