Hi,
I need to pass an variable (node identifier) via the url to an page for later use in root.ts2. Do I need to write an extra plugin for that or can it be implemeten without php?
Hi,
I need to pass an variable (node identifier) via the url to an page for later use in root.ts2. Do I need to write an extra plugin for that or can it be implemeten without php?
So far I creatend an eel helper. I assume there are saver ways ready to use to grab the parameter from the url, just not easy to find. An link to the right doc would be helpfull!
Classes/Site/Eel/Helpers/NewsIdHelper.php
<?php
namespace Site\Eel\Helper;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Eel\ProtectedContextAwareInterface;
class NewsIdHelper implements ProtectedContextAwareInterface {
/**
* Return NewsID from URL
*
* @return string
*/
public function newsId() {
return isset($_GET['newsid']) ? $_GET['newsid']:NULL;
}
/**
* All methods are considered safe, i.e. can be executed from within Eel
*
* @param string $methodName
* @return boolean
*/
public function allowsCallOfMethod($methodName) {
return TRUE;
}
}
Settings.yaml
TypoScript:
defaultContext:
‘Site.NewsId’: ‘Site\Eel\Helper\NewsIdHelper’
Root.ts2
page {
…
body.newid = ${Site.NewsId.newsId()}
…
@cache.entryIdentifier.newsId = ${Site.NewsId.newsId()}
}
root.@cache.entryIdentifier.newsId = ${Site.NewsId.newsId()}
You could try ${request.arguments.newsid}
. If you run into caching issues make sure to exclude the node from cache with
@cache { mode = 'uncached' context { 1 = 'node' 2 = 'documentNode' } }
Thank you gerhard, dropping the eel helper now, had seen that syntax but thought it requires additional router or controller settings/modifications.
I use the variable to overwrite opengrap setting in page.head.openGraphMetaTags.
Caching works if i disable caching on the affected tags (ie page.head.openGraphMetaTags.openGraphTitleTag, page.head.openGraphMetaTags.openGraphImageTag).
Or if i use the syntax i had found in the Flowpack.Listable (used for a pagination variable there).
page {
...
@cache.entryIdentifier.newsId = ${request.arguments.newsid}
}
root.@cache.entryIdentifier.newsId = ${request.arguments.newsid}
I assume the later syntax invalidates the page cache in case newsid changes, implies that newsid is used at all and above syntax completely removes caching for the openGraph tags on all pages.
The later syntax adds the request param to the hast that is generate do create this cache. So the TS-Object will be cached for each get parameter. It does not invalidate the cache, just creates a new one. So the cache is persistent. Each var that is added to entryIdentifier
will be used to generate a unique hash.
To invalidate a Cache check the entryTags
section http://neos.readthedocs.org/en/stable/CreatingASite/ContentCache.html
Or you can add the argument to your caches entryIdentifier
to get your object cached for each argument. Check JohannesSteu.Neos.News/Resources/Private/TypoScript/NodeTypes/NewsList.ts2 at master · johannessteu/JohannesSteu.Neos.News · GitHub as an example. The list is cached for each page in the pagination
You’re right! Creating caches for each parameter sounds more reasonable than uncaching the whole page (unless there will be 1000000 different parameter values that would flood your standard cache). But just uncaching the section where the parameter is used probably won’t hurt too much either. I would just do some performance testing.
Thank you both for replies and explanations. Using entryIdentifier seems like the best option, there will be about an dozend of different values.