[TYPO3-dev] typoscript rendering: setting cookie and reading during runtime not working?

Stephan Schuler Stephan.Schuler at netlogix.de
Wed Jan 2 12:41:35 CET 2013


Hey Simon.

If it's only for google analytics code: Why not simply write JavaScript that handles this?
It's very easy to create static java script which is the very same on every page but fetches stuff like cookies and only adds google analytics based on such a condition completely on client side.

If you create typo script based on condition, I'm not completely sure how this interacts with caching.

I guess that this does not play nice with caching, because the cache identifier uses very view parameters (id, L, mp, chash and another one I currently can't remember). So if you create conditions that are based on "internal values", they most likely get cached once with the current values and don't create different output if they change unless the cache is cleared or the page or plugin is set to no-cache.

And always think about clients that don't have cookies enabled. It's one thing to have an online shop which can't be used without java script. If you rely on your clients to have java script enabled: Fine. It's up to you to determine which amount of unsatisfied customers this will produce and if you can afford it.
But it's a completely other thing if you create frontend output that relies on having cookies enabled and, additionally, is capable to render different output for google. It's very easy to create output that only a view (including google) clients will ever see.
But as soon as google uses a single enhanced crawler instance which, compared to all the other google crawler instances, *can* understand cookies and detects that this one receives differently rendered output, you can easily get punished by google. Even if you didn't do it purposely.

Regards,
Stephan.



Stephan Schuler
Web-Entwickler

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de
-----Ursprüngliche Nachricht-----
Von: typo3-dev-bounces at lists.typo3.org [mailto:typo3-dev-bounces at lists.typo3.org] Im Auftrag von Simon Schaufelberger (Schaufi)
Gesendet: Mittwoch, 2. Januar 2013 12:02
An: typo3-dev at lists.typo3.org
Betreff: Re: [TYPO3-dev] typoscript rendering: setting cookie and reading during runtime not working?

Hi Stephan
thank you for taking so much time to reply me in such a clear way.

> Nice to see that it works :)

yes it really does!

Yeah, i think my problem is that the condition is parsed before the execution of the userfunction.

I really want client side storage, i just broke my complex logic down so that you can understand the important stuff without the rest.
i want to use this snippet for a shop system and if a parameter/referrer or whatever is set at the very first time requesting the page, the cookie should be set and a different output (in my case google analytics
code) will be rendered. i just need the ga code the very first time and not just the second hit ;)

the simplest idea is to copy the different output rendering into the [globalVar = _COOKIE|myCookie =] part as well. I think this is the way how i will do it now.

Regards, Schaufi

Am 02.01.2013 11:27, schrieb Stephan Schuler:
> Hey Simon.
>
> You are mixing different (and very distinct) phases of typo script parsing.
>
> The first thing: I didn't know if "globalVar _COOKIE" is supposed to work at all. Didn't try it, ever. Nice to see that it works :).
>
> Second thing: You cannot write a cookie by typo script rendering and read it by condition in the same click. At least not by pure typo script object calls.
>
> Typo script parsing basically looks like this:
> 1: Determine page id.
> 2: Fetch all typo script records for the page id, and fetch linked typo script records as well as files recursively.
> 3: Concatenate all records and files to one single string.
> 4: All conditions are parsed, which means not matching parts are skipped out. That's the part where your condition matches.
> 5: Now the remaining long typo script string is parsed as a whole,
> being transferred to from string to array structure
> 6: Here comes the execution of the array, which is the first part that touches your userFunc to set the cookie.
>
> I only mentioned logical steps of typo script parsing. There might be steps that are bound to each other or called inside another since it's an easy improvement.
> But as you can see, the condition stuff is done long before the execution is performed.
>
> Third thing: Like Nicolas said, you should not use client side storages such as cookies to determine a single rendering path.
> If you want to make different rendering steps (plugins, usually) work together, you could simply use a singleton object inside your PHP logic. You even don't need to put this into a cookie or session. If you simply want to make a single plugin store data that is fetched by another plugin later: A class extending t3lib_Singleton is just fine. Drop your data there and fetch it later. This object is destroyed when the TYPO3 process ends.
> If you want to let a plugin decide which overall output schema to use(say, one column for shoping basket, two columns with right-side adds for checkout-confirmation with the ability for editors to change this content by default content backend): Don't do it. Use different plugins on different pages. That's much more stable and much less confusing. Think about later debugging in case of some bugs. You don't want to have complexity here.
>
> Fourth thing: If you really want to make your typo script read and write a cookie within a single rendering cycle, there I currently see two different ways.
> 1: Use different userFuncs for that. This doesn't interact with condition, but it might work with the typo script "if" clause.
>
> http://typo3.org/documentation/document-library/core-documentation/doc
> _core_tsref/4.7.0/view/1/5/#id553579
>
> 2: Use a user defined condition which always returns "TRUE" but internally checks your cookie and writes it if necessary.
>
> http://typo3.org/documentation/document-library/core-documentation/doc
> _core_tsref/4.7.0/view/1/4/#id790103
>
>
> Regards,
> Stephan.
>
>
> Stephan Schuler
> Web-Entwickler
>
> Telefon: +49 (911) 539909 - 0
> E-Mail: Stephan.Schuler at netlogix.de
> Website: media.netlogix.de
>
>
> --
> netlogix GmbH & Co. KG
> IT-Services | IT-Training | Media
> Andernacher Straße 53 | 90411 Nürnberg
> Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
> E-Mail: info at netlogix.de | Internet: http://www.netlogix.de
>
> netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA
> 13338) Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH
> (HRB 20634)
> Umsatzsteuer-Identifikationsnummer: DE 233472254
> Geschäftsführer: Stefan Buchta, Matthias Schmidt
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: typo3-dev-bounces at lists.typo3.org
> [mailto:typo3-dev-bounces at lists.typo3.org] Im Auftrag von Simon
> Schaufelberger (Schaufi)
> Gesendet: Mittwoch, 2. Januar 2013 02:05
> An: typo3-dev at lists.typo3.org
> Betreff: [TYPO3-dev] typoscript rendering: setting cookie and reading during runtime not working?
>
> happy and blessed new year! this is the first post in the new year ;)
>
> i thought i have some understanding about typoscript rendering but now i am really stuck.
>
> what i want is: set a cooki e at typoscript runtime and read it later in a condition and render a different page output if its there.
>
> Problem: the condition is only true after reloading the page.
>
> Why is this code not doing what i want?
>
> in the userfunction i just call setCookie...
>
> page = PAGE
>
> [globalVar = _COOKIE|myCookie =]
> includeLibs.setCookie = fileadmin/setCookie.php page {
>          1 = USER
>          1 {
>                  userFunc = user_setCookie
>          }
> }
> [end]
>
> [globalVar = _COOKIE|myCookie = 1]
> page {
>          2 = TEXT
>          2.value = cookie is there
> }
> [end]
> --
> Regards, Schaufi
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev
>   call setCookie...
>
> page = PAGE
>
> [globalVar = _COOKIE|myCookie =]
> includeLibs.setCookie = fileadmin/setCookie.php page {
>          1 = USER
>          1 {
>                  userFunc = user_setCookie
>          }
> }
> [end]
>
> [globalVar = _COOKIE|myCookie = 1]
> page {
>
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev


More information about the TYPO3-dev mailing list