Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a way to display a structured variable #59

Open
plsnp opened this issue Sep 3, 2020 · 2 comments
Open

a way to display a structured variable #59

plsnp opened this issue Sep 3, 2020 · 2 comments

Comments

@plsnp
Copy link

plsnp commented Sep 3, 2020

When i have a nest structure of arrays and objects and do {{var}} it concatenates all values. Instead could it print a JSON like format to see the structure? If this is not desirable with the plain {{}} maybe a function like twig's dump could be added.

@tdammers
Copy link
Owner

tdammers commented Sep 9, 2020

This is easily possible; for example, sprinkles provides json() and yaml() as functions / filters in its default template context.

However, I did't want to include such a function in the core ginger library, for three reasons: first, because the exact formatting you want will differ between applications, and whatever default we offer is likely going to be not quite what you want; second, because it would increase code size, dependency footprint, etc., for questionable gains; and third, because the structure of GVal is such that it's not always obvious what the dump should look like. In PHP, a value can be a sorted-hashmap-from-hell ("array" in PHP terminology), a byte array (confusingly called "string" in PHP), a number, etc., but never more than one of them - but a GVal may or may not offer conversions to any number of these, and it's not automatically clear which one you want.

In other words, if asDict is Just, then that doesn't mean that the value is a dictionary; it just means that a meaningful conversion to or representation as a dictionary exists. But there may also be a meaningful HTML representation, textual representation, list representation and/or numeric representation for such a value - and there is no general mechanism to tell which one you wanted.

@plsnp
Copy link
Author

plsnp commented Sep 9, 2020

Maybe there can be a dump() function that prints something as a haskell value / type that indicates that it can have multiple representations?

For my use case though json() seems to have already enough debugging capabilities so i'm happy with that :) I see it's listed here https://ginger.tobiasdammers.nl/guide/syntax/filters/ which confuses me a bit since you say it's in sprinkles ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants