Printing arbitrary JSON data - feedback on my approach

50 views
Skip to first unread message

Rob Shepherd

unread,
Jun 21, 2016, 7:37:30 AM6/21/16
to Pebble Templating Engine
Hi,

I enjoy feeding initial data for javascript client scripts into the page at render time, rather than make further HTTP requests for data.
(I've used this approach quite satisfactorily on Thymelaf etc)

Here is a Gist which shows how i've implemented this in Pebble.



It works fine, and I can output arbitrary JSON data.  

Notice I must use...

| raw


...to get plain JSON data.

Is there a better way?

Thanks

Rob

PS, You may notice I'm using a custom syntax to avoid handlebars {{}} on the servside, as I use handlebars/angular on the client side.


Nick Merlo

unread,
Jun 27, 2016, 3:03:24 PM6/27/16
to Pebble Templating Engine
Looking at the documentation,  you would need to change your function to return an instance of SafeString instead of String.  Pebble will then omit escaping the result

Rob Shepherd

unread,
Jul 8, 2016, 7:50:37 PM7/8/16
to Pebble Templating Engine
Thank Nick.  Works great.
Reply all
Reply to author
Forward
0 new messages