문제

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.

도움이 되었습니까?

해결책

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

templateData:
    emailAddresses:
        support: -> docpad.pluginsTemplateData.obfuscate("some test")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top