I am trying to match a bibliography style with biblatex-philosophy. The format for online resources are as follows:
Online with author:
Online without author (same details for simplicity's sake):

By default, using this code (already with a couple of tweaks to formatting):
\documentclass[11pt, parskip=false]{scrartcl}
% Bibliography preamble
\usepackage[giveninits=true, style=philosophy-modern, yearleft=true, dateabbrev=false]{biblatex}
\addbibresource{testbib.bib}
\DeclareFieldFormat[online]{title}{#1}
\renewcommand{\postsep}{% Add comma to end of author section
\addcomma
\null\par\nobreak\vskip\postnamesep%
\hskip-\bibhang\ignorespaces}
\DeclareFieldFormat{urldate}{% Reformats urldate field to read "accessed", replacing "(visted on)"
accessed %
\thefield{urlday}\addspace
\mkbibmonth{\thefield{urlmonth}}\addspace%
\thefield{urlyear}\isdot}
\renewbibmacro*{url+urldate}{% Makes URL begin on a new line, adds comma after URL, before URLdate
\printunit{\newline}\usebibmacro{url}%
\iffieldundef{urlyear}
{}
{\setunit*{\addcomma\addspace}%
\usebibmacro{urldate}}}
\begin{document}
Sentence containing citation \parencite{blogWithoutAuthor, blogWithAuthor}.
\printbibliography
\end{document}
With this .bib file:
@online{blogWithoutAuthor,
date = {2018},
title = {Historians in the News},
maintitle = {History Matters},
organization = {The University of Sydney},
url = {http://blogs.usyd.edu.au/historymatters/2018/02/historians_in_the_news_2018.html},
urldate = {2018-02-23}
}
@online{blogWithAuthor,
date = {2018},
title = {Historians in the News},
maintitle = {History Matters},
organization = {The University of Sydney},
url = {http://blogs.usyd.edu.au/historymatters/2018/02/historians_in_the_news_2018.html},
urldate = {2018-02-23},
author = {McDonnell, Mike}
}
Outputs this:
As you can see, there is no website title (in addition to the page title) and by default the philosophy-modern settings replaces author with title when author is not present.
I added the following code to the above to make the field "maintitle" (serving as website title) recognisable to the online bibdriver, as well as cutting out the author field completely:
\usepackage{xpatch}% Modifies online bibdriver to remove author field, and add maintitle field after title
\xpatchbibdriver{online}
{\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}}
{\usebibmacro{date+extradate}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}%
\newunit\newblock
\usebibmacro{maintitle}%
\newunit}
{}
{\typeout{failed to remove author field, add maintitle field to driver for 'online'}}
Which outputs this:

Great, except obviously as I've removed the author macro from running, I don't get any author even when one is specified.
My question is, how do I run the xpatch snippet above conditionally, only when author is absent (undefined?), in order to match the required formatting?
I'm only still getting my head around xpatch command, so I doubt if my attempt is optimal anyway. Please let me know how the code could be improved.


\DeclareFieldFormat{urldate}to change the format or theurldate. The default English localisation uses American-style dates, if you want Australian-style dates, loadbabelwithaustralian. – moewe Feb 23 '18 at 07:52