I need to pass the logged-in user's email address as a variable to a embedded javascript form. I think the easiest way for me to do this is to dynamically embed the user's email address in the embed code URL.

Within the javascript snippet in the HTML block would be a URL "form=http://www.formsite.com/formname?email=XXXX@XXX.COM" -- how can I pass the logged in user's email into that?

I'm not a web developer nor do I have a lot of experience with craft other than as an admin level user. I'm trying to accomplish this without enlisting the services of a web developer to do any custom work.


There is a currentUser global variable that is available to all Twig templates.

If there is a currently logged in user, it will return that user's UserModel class.

From there, it's just a matter of:

{% if currentUser %}
    form=http://formsite.com/formname?email={{ currentUser.email }}
{% endif %}

Of course, what's inside the if block will look different depending on how you're generating the embedded code URL.

| improve this answer | |
  • Thank you Brad. I did a bit more digging to figure out all that I needed to do. I created a new matrix field / block , created the html page for it (using your example) and, Voila! I'll be able to build on this. – Jon Jan 11 '18 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.