Bring Data into HTML field in the DocType

Hi,

I need to show the data from the database table into the HTML field of the Doctype ( custom created with ‘Setup’ Document Type).

Anybody know how to display data in the HTML field,while loading the custom created doctype.?

  1. Create html template
    e.g. https://github.com/gaurav-naik/andesit_karang_anyar/blob/develop/andesit_karang_anyar/public/js/templates/driver_list.html
  2. add it to build.json - https://github.com/gaurav-naik/andesit_karang_anyar/blob/develop/andesit_karang_anyar/public/build.json
  3. add app_include_js in hooks - https://github.com/gaurav-naik/andesit_karang_anyar/blob/develop/andesit_karang_anyar/hooks.py#L20
  4. Changes in doctype’s py https://github.com/gaurav-naik/andesit_karang_anyar/blob/develop/andesit_karang_anyar/andesit_karang_anyar/doctype/vehicle/vehicle.py
  5. Changes in doctype’s js - https://github.com/gaurav-naik/andesit_karang_anyar/blob/develop/andesit_karang_anyar/andesit_karang_anyar/doctype/vehicle/vehicle.js

This shows driver’s photo under Vehicle.

11 Likes

@revant_one
Thank you for the detailed reply…
Let me try

@revant_one Thank you for putting this out here! I am trying to understand what’s going on in the python and JS portions of your app. I am trying to strip it back to something super simple and I’m getting hung up on the way your app brings in the HTML template.
Sorry for resurrecting this thread, but I think this is a really helpful technique if I could get it working.

1 Like

frappe.render_template used in javascript returns rendered html string.

It takes 2 parameters,
template name e.g driver_list
and dictionary e.g. cur_frm.doc.__onload.

template names are defined using the first three steps 1) create a John Resig template HTML, 2) add it to build.json, 3) add it to hooks so it is available for app.

reference : http://stackoverflow.com/questions/1775051/how-to-use-the-john-resig-javascript-micro-templating-engine

instead of using tmpl() use frappe.render_template()

example using render_template in desk page

template file defined here

changes in hooks

add template to build.json

Can it be done for the web forms?

If you wish to build a custom functionality into web pages refer how current pages from www directory work.

also check documentation for portal development :
http://frappe.github.io/frappe/user/en/guides/portal-development/