0
votes

I configured the extension tt_address in my page. I need to filter the address by its year. So I build a select box. I need to append some query parameter with its url to access in controller for implementing the filter. The functionality is done successfully. But realurl is not working for this particular functionality.

main.js

function initYearFilter() {
    var selectedItem = sessionStorage.getItem('year');
    if (selectedItem !== null) {
        $('.year-filter select').val(selectedItem);
    }
    $('.year-filter select').on('change', function () {
        var loc = location.href.match(/.*people\/alumni\/+/)[0],
            url;


        if ($(this).val() == 'reset') {
            url = loc + '?no_cache=1';
        } else {
            url = loc + '?ts_address[year]=' + $(this).val() + '&no_cache=1';
        }

        sessionStorage.setItem("year", $(".year-filter select").first().val());

        window.location.href = url;
    });
}

My realurl config

'postVarSets' => array(
            '_DEFAULT' => array(
                'year' => array(
                    array(
                       'GETvar' => 'ts_address[year]',
                    ),
                ),
              ),
              )
2
Javascript in client browsers, does not know about TYPO3, Cache Hash and RealUrl. You need to use TYPO API to generate linksjokumer
When we call window.location.href the page is reloaded .Aswathy S
As @jokumer said linkbuilding only works from inside TYPO3 API. You'd either have to build all the possible link combinations in advance. Or create an ajax request which can return the prober url for you.Toke Herkild

2 Answers

1
votes

Don't let urls being generated manually in frontend, like you do in Javascript.

My advice here would be to generate the urls backend side and attach it to a option attribute (data-reset-url, data-url).

// maybe a foreach here
  $GLOBALS['TSFE']->cObj->typolink_URL([
      'parameter' => '_PAGEUID_',
      'additionalParams' => '?ts_address[year]=' . $year, // suppose in foreach have year var
      'no_cache' => true
  ]);
0
votes

If you think ext:realurl is the culprit deactivate ext:realurl and look if it works then.

I think it still will not work, but you will see something in the url that should give you the neccessary hint.
You probably stumble over a security feature of TYPO3: cHash.
With a cHash URL parameter TYPO3 secures it's URLs against injection of unrelated parameters for a cached version of a page. If TYPO3 builds an URL it hashes all parameters and appends this hash to the url. If such a cHash is found in an URL the parameters are fetched from database and all current URL parameters are ignored. especially any additional parameters. So the cached page matches the given url.

If you use ext:realurl, this cHash parameter is hidden in a 'normal' URL path. If you add parameters, like in your javascript, they are removed as they are not encoded in the cHash, which is encoded in the speaking URL.

In your case the additional parameter would change the content of the page. This page could be cached if the additional parameter is included in a cHash.
Here you must help realurl to either build an URL without cHash, or build URLs which contain these individual cHashes:
You could build a menu of available years and also configure a pathsegment for the year. In this way you can get individual cHashes for each year. You need to change your javascript to add a path-segment instead of a parameter.