Twig usage examples in Open EMR

I’m working on changes to the patient portal and was wondering why Open EMR does not take advantage of Twig to build layout templates?

It would help with standardizing development and make it much easier to attract contributors, I’ve been trying to find an example of twig usage in Open EMR but besides a few handful of files where it’s mentioned theres not one where I can see how I would use it in Open EMR.

Anyone got any pointers? Thanks.

Over the years although internal architecture has evolved quite a bit, very few new screens have been added to this product. That means Twig implementation will consist of replacing existing pieces of code that have passed certification with a completely new set of ui code. That is never exciting or cost effective.

If one has to start somewhere, I would suggest reports. Bootstrap’s menu forms can be used to set the report parameters used by that report’s model code. Resulting data objects can then be passed on to a set of standard templates that handle layouts, column sorting, paging and printing without any further development efforts.

In its simplest form we should have a fully functional “report” by providing a single sql view.

hi @benmarte ,
Check out this PR: https://github.com/openemr/openemr/pull/2862
(it was going to be OpenEMR’s first twig commit, however, the weno module then took another direction, so PR didn’t get into codebase)

@benmarte, I definitely don’t know anything about weno module setup. But templates/weno/narcotic.html.twig in that PR is how even smarty templates are implemented in existing codebase. If the template is going to be used only once for a specific page (for now and mid-term future), not sure if the whole effort is justified.

Developers can leverage existing assets if, as an example, a template when provided with an associative array, converts all keys into labels and all values into existing values of input fields, adds update and cancel buttons to create a standard form. Now the new contributor can spend more time on manipulating data models rather than html tags, font sizes, bootstrap classes and responsiveness issues.