TYPO3 Flow Base DistributionPackagesApplications

Suggestion #3677

embed.javaScript

Added by Steffen Ritter about 6 years ago. Updated about 2 years ago.

Status:New Start date:2009-06-16
Priority:Could have Due date:
Assigned To:- % Done:

0%

Category:-
Target version:-
Has patch:No Tags:

Description

Hi,
if you wanna put Inline JS into your fluid template your validation may fail if you lack the CDATA Section.

If you wanna call internal ViewHelpers in JS you cannot set CDATA manually in the template

--> Need for a ViewHelper

Attached is a ViewHelper I'm currently using and satisfying this.

Turns

<f:js>
    Ext.get('BezirkeSearchField').on('keypress', function(){
        BezirkeAjaxSearch.delay(500); 
    });
    Ext.Ajax.url = '<f:uri.action action="ajax" />';
</f:js>

into


<script type="text/javascript">
    /* <![CDATA[ */

    Ext.get('BezirkeSearchField').on('keypress', function(){
        BezirkeAjaxSearch.delay(500); 
    });
    Ext.Ajax.url = '...?tx_rsbezirke_pi1%5Baction%5D=ajax&tx_rsbezirke_pi1%5Bcontroller%5D=Street';

    /* ]]> */
</script>

It's pretty simple...
Thanks for taking care.

regards

Steffen

JSViewHelper.diff Magnifier - Adding JsViewHelper to Fluid (2.8 kB) Steffen Ritter, 2009-06-16 08:10

3677_v1.patch Magnifier (9.8 kB) Bastian Waidelich, 2010-06-23 14:52


Related issues

related to TYPO3.Fluid - Bug #8879: { } when using as JavaScript Closed 2010-07-15

History

#1 Updated by Sebastian Kurfuerst about 6 years ago

  • Project changed from Extbase MVC Framework to TYPO3.Fluid
  • Category deleted (432)

#2 Updated by Sebastian Kurfuerst about 6 years ago

Yep, we definitely need this. I'm just thinking whether a name "javaScript" would be better because it is more explicit.

What do you think?

Greets,
Sebastian

#3 Updated by Christian Müller about 6 years ago

I would like to have javaScript, its easier to read in a template and understandable by anyone.

#4 Updated by Steffen Ritter about 6 years ago

Both fine with me...

#5 Updated by Bastian Waidelich about 6 years ago

  • Category set to ViewHelpers
  • Assigned To set to Bastian Waidelich
  • Target version set to 1.0.0 alpha 2
  • Branch set to v4 + v5

Sebastian Kurfuerst wrote:

I'm just thinking whether a name "javaScript" would be better because it is more explicit.

I think so too. And it should have a src-attribute too.
I'll take care of it, thanks for the patch!

#6 Updated by Steffen Ritter about 6 years ago

Bastian Waidelich wrote:

I think so too. And it should have a src-attribute too.
I'll take care of it, thanks for the patch!

Hey,
what is the current state ?

regards

Steffen

#7 Updated by Bastian Waidelich about 6 years ago

Steffen Ritter wrote:

Hey,
what is the current state ?

We're thinking about a more generic approach, but we're on it! Sorry for the delay!

#8 Updated by Robert Lemke about 6 years ago

  • Target version deleted (1.0.0 alpha 2)

#9 Updated by Bastian Waidelich almost 6 years ago

Still thinking about this one..
Take this scenario:

<link href="foo/bar.css" rel="stylesheet" type="text/css" />

<style type="text/css">/*<![CDATA[*/
  // some inline css rules
/*]]>*/</style>

<script src="foo/bar.js" type="text/javascript"></script>

<script type="text/javascript">/* <![CDATA[ */
  // some inline js
/*]]>*/</script>

What would be a nice and consistent way of achieving the above?

#10 Updated by Bastian Waidelich about 5 years ago

  • Priority changed from Must have to Should have

#11 Updated by Bastian Waidelich about 5 years ago

  • File 3677_v1.patchMagnifier added
  • Status changed from New to Needs Feedback

Attached patch adds a viewhelper "embed.javaScript".
But after discussing with Karsten, I'm not sure anymore if we really need a viewHelper for this.. The drawback is, that we'd lose the direct preview (opening the template in a Browser).
The missing CDATA tags for inline JavaScript might be added automatically by another Fluid interceptor.. But I'm not sure about this one.
Please comment!

#12 Updated by Sebastian Kurfuerst about 5 years ago

hey, I'd rather suggest to create a ViewHelper which outputs the CDATA stuff. Doing that via an interceptor would be too much magic IMHO.
Greets, Sebastian

#13 Updated by Bastian Waidelich about 5 years ago

  • Tracker changed from Feature to Suggestion
  • Project changed from TYPO3.Fluid to Fluid - ViewHelper - Incubator
  • Category deleted (ViewHelpers)

#14 Updated by Bastian Waidelich about 5 years ago

  • Subject changed from Add Fluid ViewHelper for Inline JavaScript to embed.javaScript

#15 Updated by Bastian Waidelich about 4 years ago

  • Status changed from Needs Feedback to Rejected
  • Priority changed from Should have to Won't have this time

As described above, replacing the script tags would have negative side effects.
Creating a cdata view helper that wraps its child nodes in CDATA tags seems like an overhead to me..

See http://forge.typo3.org/projects/typo3v4-mvc/wiki/FAQ#How-can-I-use-JavaScript-inside-Fluid-templates for more details on how to use javascript in Fluid templates.

And feel free to reopen if you don't agree.

#16 Updated by Felix Nagel over 2 years ago

Linked wiki FAQ point results in inline JS within the body which is just bad practice.

A real JS helper for adding inline JS is still missing. This should be done by using $GLOBALS['TSFE']->getPageRenderer()->addJsInlineCode like in EXT:fed viewhelper.
TYPO3 internal merging and compressing does not work with inline body JS but with scripts / files added to pageRenderer!

Please reopen!

#17 Updated by Bastian Waidelich over 2 years ago

  • Status changed from Rejected to New
  • Assigned To deleted (Bastian Waidelich)
  • Priority changed from Won't have this time to Could have
  • Has patch set to No

Also available in: Atom PDF