0

I want to render a table which holds all entity data.

There should be a noscript version which additional renders two colomns with editing and deleting operations and a default javascript version where it gets solved dynamicaly over a sidebar.

Is there a way to let this decision to twig? So that twig detects if javascript is supported and if not renders the additional fields?

Regards

bodokaiser
  • 15,122
  • 22
  • 97
  • 140
  • 1
    Of course there is not, as twig gets executed on the server, preparing the page before it is sent to the browser. As the check if javascript is enabled is done on the client side, twig has no way of detecting this. – Sgoettschkes Apr 24 '12 at 21:47

1 Answers1

0

Twig-specific code? No

HTML code? Yes

You can make use of the <noscript>...</noscript> tag to display something to browsers without JavaScript support.

Alternatively, you can display the two additional columns to everybody and use JavaScript to hide them. This way, people without JavaScript see them, people with JavaScript don't.

simshaun
  • 21,263
  • 1
  • 57
  • 73
  • Hi, using noscript is causing a lot of overhead. Are there other solutions? – bodokaiser Apr 25 '12 at 04:41
  • As I mentioned, you could render the two additional columns for everybody, and use JavaScript to hide them. Similar to progressive enhancement. – simshaun Apr 25 '12 at 05:01
  • Hi, so far I understood you. But I meant the overhead response. – bodokaiser Apr 25 '12 at 12:02
  • 1
    If you want to avoid sending any extra code to JS-capable browsers, there is no way of detecting it in Twig. You could set a cookie using JS on every page, and look for that cookie in PHP to determine if JS is enabled, but that's only a half-way solution that will not work if cookies are disabled or the visitor hits the table page first. – simshaun Apr 25 '12 at 19:44