Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable to check for web view vs. email #246

Closed
luke-nehemedia opened this issue Aug 9, 2021 · 4 comments
Closed

Variable to check for web view vs. email #246

luke-nehemedia opened this issue Aug 9, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@luke-nehemedia
Copy link

luke-nehemedia commented Aug 9, 2021

A client of mine often includes videos in their newsletters. Since this is not really possible in an email, I only include a cover-image of the video with a link to the web-view of the newsletter in place of the video. When the user clicks on the link it opens the web-view and the video is loaded in place of the cover-image.

To implement this, I have to check whether the current render is a web-view or the email-view. It would be very handy to have a variable in place like isWebRequest to check for this.

Right now I use the following code:

{% if craft.app.controller is instance of('craft\\controllers\\TemplatesController') %}
      <mjml...>display video</mjml>
{% elseif (craft.app.controller is instance of ('craft\\controllers\\QueueController')) or (craft.app.controller is instance of ('putyourlightson\\campaign\\controllers\\SendoutsController')) %}
    <mj-image href="{{browserVersionUrl}}" target="_blank" /> Link to web-version</mjml-image>
{% endif %}

This works for the sendout-preview and the sent mail, but not for test-mails. Therefore it would be really handy to have a variable or function to check for this.

@luke-nehemedia luke-nehemedia added the enhancement New feature or request label Aug 9, 2021
@bencroker
Copy link
Collaborator

Makes sense, will try to fit this in for the next release, thanks for the suggestion!

@bencroker
Copy link
Collaborator

Looked into this and there are some other things that you should be able to check for to determine whether this is a web request or not, the simplest being whether the variables variable is defined.

{% if variables is defined %}
    This is a web request.
{% endif %}

@bencroker
Copy link
Collaborator

I went ahead and added the isWebRequest variable in 175911f for the next release.

@bencroker
Copy link
Collaborator

Released in version 1.21.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants