twigfiddle icon indicating copy to clipboard operation
twigfiddle copied to clipboard

CSV format for data

Open gabiudrescu opened this issue 5 years ago • 9 comments

I feel this fiddle should support CSV format as data format. how I plan to use this feature:

  • create some queries in MySQL for non-technical people
  • allow them to export as CSV to do their thing in Excel
  • copy paste here and then render the twig to do stuff that Excel is bad at

I can provide an implementation, if you want.

gabiudrescu avatar Jan 22 '20 10:01 gabiudrescu

The twig context is a map of variable names to variable values. I don't see how you would define that in a CSV format.

stof avatar Feb 12 '20 16:02 stof

well, I had this JSON exported from PHPStorm (DataGrip) and couldn't use it with twigfiddle as I didn't know what was the name of the object I can iterate on: https://twigfiddle.com/caaokq

hence, my thought of having a CSV that should be converted to an assoc-array that I can iterate over easily.

gabiudrescu avatar Feb 12 '20 21:02 gabiudrescu

Well, you should be doing something like {"array": [1, 2, 3, 4] } is you want to define a variable array containing that array.

stof avatar Feb 13 '20 10:02 stof

In your case you can replace array by _context._parent: https://twigfiddle.com/caaokq/2

The purpose of twigfiddle is to try and debug some twig code, I don't think I will integrate this feature.

I'm even going to remove lots of useless features such as "creation of public / private fiddles" or search filters etc in order to fit with that simple and pragmatic vision.

ninsuo avatar Feb 13 '20 12:02 ninsuo

@ninsuo note that _context._parent relies on an implementation detail of the {% for %} tag here.

stof avatar Feb 13 '20 13:02 stof

I tried to use dump() function to see the available context, but it wasn't working. any reasons why this is not available?

anyway, I understand your position and if this is not going to be included in the app,then this issue can be closed with a won't-fix resolution.

gabiudrescu avatar Feb 16 '20 09:02 gabiudrescu

Hello

Yes dump is not available because it dumps html where twigfiddle renders text/plain.

I may implement it anyway (using the same kind of architecture than the profiler). Could you create a separate issue for this?

Thanks Alain

Le dim. 16 févr. 2020 à 10:44, Gabi Udrescu [email protected] a écrit :

I tried to use dump() function to see the available context, but it wasn't working. any reasons why this is not available?

anyway, I understand your position and if this is not going to be included in the app,then this issue can be closed with a won't-fix resolution.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/ninsuo/twigfiddle/issues/67?email_source=notifications&email_token=AA7VWRHMFAN53I4WIHP5OD3RDEDI5A5CNFSM4KKDO6SKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL4CCRY#issuecomment-586686791, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7VWRFU2LAAUYPJZ3XHUQTRDEDI5ANCNFSM4KKDO6SA .

ninsuo avatar Feb 16 '20 10:02 ninsuo

the reason I wanted to use dump() function was to see what variables I have available in the twig env. instead of implementing a new dump function, I would rather list all variables in TwigFiddle UI. wdyt?

gabiudrescu avatar Feb 16 '20 17:02 gabiudrescu

Rendering the context really depends on ... the context. If you're in the main Twig file, or in an included file, or within some tags... variables in the context may change.

Thus, using the {{ dump() }} function makes sense, and without recoding it. It's more changing the default location of its result.

ninsuo avatar Feb 16 '20 18:02 ninsuo