Thread:Extension talk:ParserFunctions/Nesting a magic word within a string function?

I'm trying to execute the following function on every page that exists for an uploaded file:

So, if I uploaded a file called "File.pdf", on the wiki page for File.pdf, I'd expect to return "File". I'd expect the entire function to return something like: http://mywiki.com/mediawiki/images/4/4d/File.pdf

Instead, nothing at all is returned when PAGENAME is embedded within filepath. If I type the expression without, i.e.  , it works fine and returns: http://mywiki.com/mediawiki/images/4/4d/File.pdf

Is it just not possible to embed magic words in string functions, or am I missing some escape character or something?

Thanks in advance,