Hi, I'm new to ACL and am having trouble understanding tables and callback functions. I intend to add some tags to a recently inserted table. My first step is to add my callback function for any document to be invoked after inserting a table:
doc_add_callback(0, table_insert_after, myCB)
Unfortunately, it seems like the code within myCB is never run. No errors when adding myCB and no messages when inserting a table in the editor. Anyone knows why this is happening?
Thanks in advance,
If that line of code you included is the actual code in your ACL, then the problem is probably just missing quotes. The second and third params of doc_add_callback() should be strings. Try something like this:
doc_add_callback(0, "tbl_insert_after", "myCB");
(Note also that it is "tbl_insert_after", not "table_insert_after").
Hopefully that will get you fixed up.
Thanks for your answer. You were right about the quotes and the misspeling, however it didn't change the response. Is there any other detail to have in mind while defining the function other than the number of arguments and being stored within a file in the custom/scripts folder?
Putting the script in the custom/scripts folder isn't enough to make it run automatically. To do that, you should put it in the editinit folder, which will make it run the script every time you open a new document for editing. Or, if you want to have it only apply to a certain doctype, you can put it in the instance.acl file in the doctype directory. See the Help Center topic on custom directory structure for more information on how scripts from different locations run at different points during an editor session.
Correct, I guess what I meant is making my callback function available to the doc_add_callback() that I type in the command line for testing purposes. Once the code is tested I intend to add the callback our initialization .acl file in custom/init.
Basically, the answer is the same. Your function won't be available until you load it, and it won't load automatically unless it's in one of the startup script locations (custom/init, custom/editinit, custom/doctypes/*).
If you want to load it manually for testing purposes, use the "source" command, e.g. if your function is defined in custom/scripts/myCB.acl,
If your script file is in custom/scripts, then you won't have to add the full path, you should just be able to use the base filename with the source command.
Another potential gotcha: if you have defined a package for your script file, you will need to include the package qualifier in your doc_add_callback() call. For example, if you have this at the top of your script file:
then your doc_add_callback() call would need to look like this:
doc_add_callback(0, "tbl_insert_after", "myCallbacks::myCB");