[TYPO3-mvc] Best Practice? Passing Values to JavaScript within a Template

Tim Schoch | GSTALTIG tim.schoch at gstaltig.ch
Tue Apr 26 10:40:32 CEST 2011


Hello Bastian

Thanks for the link. My question is more a theoretical one then a technical. 
In this case, I have around 10 independent modules that can interact with each other. (Think of some Ajax Requests to load additional Content, enhancement to different parts of the page, ... )
Each of these modules runs within its own scope and the passed fluid variables can have the same name but different values for different modules. ( speed, amount of items, ... )

A workaround would be to assign them to a global object using the module name as 'namepace' ( registry.module.varName = value ). But still it's a workaround, as the registry object itself could be overridden by any other extension and you have to add support for it to all your files.

AJAX would work if you have only one or two values you need. But in my experience not very reliable for initialization and i'd rather have the initial request be larger then spam the request queue.

All Values that aren't user specific could actually be cached within the file or the plugin, like speed, show/hide flags, etc...
Is there a preprocessor for JS, something like less? Maybe it would be possible use a hook in the scriptmerger extension?
What do others think?
Tim


  _____  

From: Bastian Waidelich [mailto:bastian at typo3.org]
To: typo3-project-typo3v4mvc at lists.typo3.org
Sent: Tue, 26 Apr 2011 09:33:41 +0200
Subject: Re: [TYPO3-mvc] Best Practice? Passing Values to JavaScript within a Template

Tim Schoch | GSTALTIG wrote:
  
  Hi Tim,
  
  > I'd like to pass some values from the controller to the javascript files [...]
  
  Maybe this helps you:
  <http://forge.typo3.org/projects/typo3v4-mvc/wiki/FAQ#How-can-I-use-JavaScript-inside-Fluid-templates>
  
  > And how about Caching?
  
  You should put all "static" scripts into js files, so they can be 
  cached. Dynamic parts (like the name of your visitor) can't be cached of 
  course so you might want to insert them already before the extbase 
  output (e.g. via an TS USER_INT object) so that your extbase plugin 
  still can be cached.. Or you load the custom data via AJAX.
  
  Best,
  Bastian
  _______________________________________________
  TYPO3-project-typo3v4mvc mailing list
  TYPO3-project-typo3v4mvc at lists.typo3.org
  http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
    


More information about the TYPO3-project-typo3v4mvc mailing list