Question

I'm trying to write a docpad plugin that exposes email-obfuscation functions.

At the moment I have this:

extendTemplateData: ({templateData}) ->
  templateData.obfuscate = (emailAddress) ->
     return ### obfuscated ### emailAddress

Great, I can now use <%- @obfuscate(mail) %> in my eco templates.

But, what I would like to do is something like this

docpadConfig:
   templateData: 
      emailAddresses:
         support: obfuscate("support@mycompany.com")

So I can write <%- @emailAddresses.support %>

I would also be ok with:

support: -> return obfuscate("support@mycompany.com")

So the question is: how can I make the obfuscate function available in that spot?

I've also tried to access it through docpadConfig.templateData.obfuscate() with no luck.

Was it helpful?

Solution

You are close! You can get the plugin templateData like this:

templateData:
    emailAddresses:
        support: -> docpad.pluginsTemplateData.obfuscate("some test")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top