[Koha-devel] Embedding JSON data in HTML

Tomas Cohen Arazi tomascohen at gmail.com
Thu May 6 16:28:07 CEST 2021


Nice finding, David. I've come across that in the context of Koha and
Template::Toolkit, and did something similar, using a data- attribute. I
used [% USE JSON.Escape %] to escape the data that comes from Perl.

Here, I set the data structure to a data-pickup-locations attribute:
https://gitlab.com/thekesolutions/Koha/-/commit/8b63154b866863aae6ac981b37c98864cd8875f4#f9b348ee995ab14b7c8a47e5ef2b7fe07838ec38_811_822

And then I use it:
https://gitlab.com/thekesolutions/Koha/-/commit/8b63154b866863aae6ac981b37c98864cd8875f4#f9b348ee995ab14b7c8a47e5ef2b7fe07838ec38_1245_1274

Best regards



El mié, 5 may 2021 a las 1:07, <dcook at prosentient.com.au> escribió:

> Hi all,
>
>
>
> I was just reflecting on bugs like
> https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=26942 and
> reviewing https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
> when I saw the following method for embedding JSON in HTML:
>
>
>
> <!-- Generated by the server -->
>
> <script id="data" type="application/json">{"userId":1234,"userName":"John
> Doe","memberSince":"2000-01-01T00:00:00.000Z"}</script>
>
>
>
> <!-- Static -->
>
> <script>
>
>   const userInfo = JSON.parse(document.getElementById("data").text);
>
>   console.log("User information: %o", userInfo);
>
> </script>
>
>
>
> I thought that was neat.
>
>
>
> David Cook
>
> Software Engineer
>
> Prosentient Systems
>
> Suite 7.03
>
> 6a Glen St
>
> Milsons Point NSW 2061
>
> Australia
>
>
>
> Office: 02 9212 0899
>
> Online: 02 8005 0595
>
>
> _______________________________________________
> Koha-devel mailing list
> Koha-devel at lists.koha-community.org
> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
> website : https://www.koha-community.org/
> git : https://git.koha-community.org/
> bugs : https://bugs.koha-community.org/
>


-- 
Tomás Cohen Arazi
Theke Solutions (http://theke.io)
✆ +54 9351 3513384
GPG: B2F3C15F
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20210506/7006439d/attachment.htm>


More information about the Koha-devel mailing list