You can set header arguments in Org mode properties (see (org) Using Header Arguments) to avoid repeating, for example, all code blocks in this org file will have :dir /tmp
#+PROPERTY: header-args :dir /tmp
I also have the following command in my init file, it duplicates the last src block's header, ...
Here's an implementation using org-babel-post-tangle-hook as I hinted in my comment:
#+PROPERTY: header-args:yasnippet :mkdirp yes :padline no
#+begin_src yasnippet :tangle ./snippets/a
# key: a
a foo bar
#+begin_src yasnippet :tangle ./snippets/b
# key: b
b foo bar
* Code ...
You can define an abbrev that uses the function you defined:
(define-abbrev perl-mode-abbrev-table "vd" "" #'print-dumper))
Don't forget to turn on abbrev-mode as a minor mode in your perl buffers:
(add-hook 'perl-mode-hook #'abbrev-mode)
Alternatively, you can probably define conditional ...
You can delete chars from the buffer during expansion, but modifying the buffer during expansion is dicouraged.
Deleting chars is pretty easy, because yasnippet allows to eval elisp code during expansion. You have to put this code into back-quotes Read more about it here.
Your snippet would then look like this example (you need to refine this crude example,...
You can do this with an extra step (see "Nested placeholder fields" in the manual):
With the optional field: TAB, TAB, insert field 1, TAB, insert field 2, TAB to exit. Without the optional field: TAB, C-d, insert field 2, TAB to exit.
Another option is to use a function that deletes the empty field in case it finds one:
In your buffer, M-x yas-visit-snippet-file, then type the name of the snippet you want to edit, or choose from a prompted list. Then it will open a buffer for you to edit. From the buffer you can M-: buffer-file-name to see the path of the file containing the snippet.