Keisuke Miyako presents 4D Tags at 4D Summit 2016

Automatically translated from English

Keisuke Miyako, Technical Service Manager from 4D Japan, presents at 4D Summit Paris 2016 how the 4D transformation tag feature has been highly empowered with 4D v16. If you are not using 4D tags yet – be sure you’ll be thrilled to start using it asap after watching that video!

Besides the introduction of the enhancements done in 4D v16 making 4D tags now so powerful, Keisuke presents here 2 concrete examples of 4D tags use cases: export data to an Excel spreadsheet and create nice charts using a JavaScript library from data served in a JSON format.

Templating principle

4D tags allows you to take significant shortcuts in any new development that involves XML, HTML, or just about any kind of template-based data processing tasks. Just use PROCESS 4D TAGS to generate the text-based file that exactly fits your needs.


Instead of writing complex code to procedurally build structural documents based on 4D data, from scratch, you can take a ready made, well-formatted example document, add blocks of 4D code using the various 4D tags at your disposal, and use that as a template.

Whats’ new in 4D v16?

Maybe you are already familiar with existing 4D tags: 4DTEXT, 4DLOOP, 4DIF, 4DHTML… 4D v16 actually provides you with great new features and tags, opening wide possibilities:

  • the new 4DCODE tag
  • the new $ syntax providing much more flexibility than the usual syntax based on HTML comment syntax <!– >
  • and the possibility to debug your code inside the template!

New 4DCODE tag

4DCODE tag is pretty similar to the 4DEVAL tag. But otherwise 4DEVAL which evaluates a single 4D expression, 4DCODE allows to insert 4D code across multiple lines. Thus, you can just copy your existing method or a block of code and paste it inside your 4DCODE tag in your template document.

ALL RECORDS:C47([Product:1])
ORDER BY:C49([Product:1];[Product:1]name:2)
ARRAY TEXT:C222($paramNames;0)
WEB GET VARIABLE:683($paramNames)
C_LONG INT:C283($f)
$f:=Find in array:C230($paramNames;"year")
    ALL RECORDS:C47([Inventory:2])
End if

You can in fact use as many 4DCODE tags as you like in your templates. You can query the database, you can use arrays, pointers, objects. basically you can do anything you could do in your 4D methods.

4DCODE not only allows you to include 4D code in free-hand mode, it also gives you the ability to trace and debug that code. Just use the TRACE command in your 4D tags template, and the debugger will be opened when the tags are processed!

Use command numbers

In the example given above, you surely noticed the :Cxx suffixes, added at the end of each command. The number in the suffix is actually the command number. For instance, 47 is the command number for the ALL RECORDS command.

This is optional, but it is a future-proof way of writing 4D code in plain text. It avoid encountering issues after a 4D command has been renamed but also allows you to use French 4D command names in your 4DCODE tag and run it on an English system environment. You can even go further by completely avoiding the whole command name and just use :Cxx, that’s it!

Please also note that the :Cxx suffixes can automatically be generated using the Code with tokens option of the METHOD GET CODE command, of course you do not need to do it manually!

New $ syntax for more flexibility

Instead of using HTML comments, it is now possible to use the “$” symbol before the 4DEVAL, 4DTEXT and 4DHTML tags and pass between brackets any 4D expression you need to evaluate. For instance:


This new syntax gives you now the ability to put 4D tags inside a XML attribute for example, where you are not allowed to use the “<” and “>” signs. This provide the developer with more flexibility regarding how or where you will use 4D tags.

Want to know more about this? Check out this post for more information about this new syntax.

Caroline Briaud

• 4D Product Team Leader •

Caroline joined 4D SAS in July, 2013 as an Engineering Manager responsible for new features definition. Caroline helped the Engineering team to put in place the R-release concept, with the new development process definition and its application within 4D’s engineering teams.Caroline is now leading the 4D Product team, mainly made up of Product Owners which are representing the customers within Engineering.

Caroline started her career as a software developer in the mobile phone industry. She specialized in program management with an American company in an international context spread across US, India and China.