I'm creating an email template using Kentico's email marketing module. In which I have an email widget that retrieves and fills in holiday detail parameters based on some custom contact field values therefore making this dynamic for each user.
How can I pass custom contact fields in to the widgets from the recipient? The recipient object only contains set values.
Contacts for this email campaign are collected from a form submission that passes in the required values.
<div style="display:none;">
{% holidayDate = Recipient.GetValue("holidayDate"); #%}
{% holidayId = Recipient.GetValue("holidayId"); %}
{% ItineraryData = customNamespace.GetItineraryItem(holidayId, holidayDate) #%}
</div>
<h2 class="price">{% ItineraryData.GetValue("Price") #%}</div>
Something like the above is what I am trying to achieve but I can't seem to work out how to get these custom fields to use in the email widget.
Thanks,
Luke
The documentation states Recipient only has 4 available fields:
FirstName
LastName
Email
PersonaID
If you want to get custom fields, you'll have to look up the contact by the email address, first and last name in a macro.
Related
I wanted to build a commerce website using craft 3 cms. And I wanted to create parent registration form so each parent will have an account to use on the site. Then after they sign in I want them to be able to add their children.
Is this possible to do using craft 3 cms. The only thing I found is user registration form on the documentation.
If there is a blog of documentation to integrate this feature using craft 3 cms or is there anything I missed so far.
It depends how complex your parent - child relation will be.
The best solution would be is to write a custom plugin or module for that, with records and rules, some controllers ...etc
My solution would be the following
Allow public registration
Create two user groups:
Parent
Child
Set the default user group to Parent
Make sure the user group Parent has the permission:
Assign User Groups -> Assign users to "Child" checked
Create a field group with one field in it:
parentId > number (more precisely int)
Assign this field group to the users
Create a front-end user registration form for the parents so they can register.
And then you will need one more form for the parents, so they can register their children.For this, the parents are required to be logged in, otherwise it won't work.
You can check this with
{% if not craft.app.user.isGuest %}
{# Your child registration form #}
<input type="hidden" id="parentId" name="parentId" value="{{ craft.app.user.id }}">
{% else %}
{# The user is not logged in #}
{% endif %}
This way you can:
Differentiate Parent users from children using:
{% set userGroups = craft.app.user.identity.getGroups() %}
Get the logged in child's parent user object using:
{% set parent = craft.users().id( craft.app.user.identity.parentId ).one()%}
Get the logged in parents children
{% set children = craft.users().parentId( craft.app.user.id ).all() %}
Say I have a form named myform with an input field named myinput. By default, symfony will generate HTML widget like:
<input name="myform[myinput]" ... >
This doesn't work with my current javascripts and I need to get the following instead:
<input name="myinput" ...>
I've searched quite a bit and found 2 ways to achieve this:
return null in getBlockPrefix() method in form type class.
create the form using FormFactoryInterface::createNamed() and pass null as name.
It seems like the first method is not recommended, since it would limit the ability to customize form rendering using prefixed blocks.
The 2nd method was recommended here and here.
However both methods will change the name of the form to null and as a result symfony will generate the form like:
<form name="" ...>
This is probably because form_div_layout.html.twig looks like:
<form name="{{ name }}" ...
Which doesn't validate as HTML5.
According to this page, "this is not a bug".
I know I can override the form_start block in the template and remove the name altogether, but it seems that the form wasn't designed to be used with null names in general (hence no check for name length in the template).
So my question is: What is the recommended and HTML5 compatible way to remove input name prefixes for symfony forms?
It was a bug in form rendering. I've submitted a pull request to symfony repo which was accepted.
Until the change is released, a temporary solution would be to add this code to your form theme:
{# fix HTML5 validation of forms with null names #}
{% block form_start %}
{% set name = name|default(block_prefixes.1) %}
{{ parent() }}
{% endblock %}
Regarding PHP, I think either option is OK.
Regarding Twig, I'd go for creating a custom form theme and, optionally, apply it to all forms on the site. I think that's the Symfony way of rendering a form according to your, specific, needs (nullable form name).
Sending transactional apis through SendGrid. My template (ported over from Mailchimp) has conditionals (e.g.
*|IF:SHOWTHISSECTION|*
in Mailchimp syntax). This includes or excludes sections of the template based on a variable.
I can't find the analog in SendGrid, does it simply not have this capability? I'd like to suppress certain sections depending on the presence/absence of a substitution variable.
SendGrid supports this natively now:
{{#if user.profile.male}}
<p>Dear Sir</p>
{{else if user.profile.female}}
<p>Dear Madame</p>
{{else}}
<p> Dear Customer</p>
{{/if}}
Reference: https://sendgrid.com/docs/for-developers/sending-email/using-handlebars/#conditional-statements
It's a horrible hack, but by introducing new variables and using CSS, you can hide the relevant portions of mails using display. So where before in Mandrill/MailChimp I'd have something like:
*|IF:FAKEVAR|*
<p>Show some text here</p>
*|END:IF|*
Instead, introduce a new variable IF_FAKEVAR, whose value is either "none" or "inherit" depending on whether FAKEVAR has a value, then do this:
<p style="display: *|IF_FAKEVAR|*">Show some text here</p>
While it's a hack, for very complex email templates, it avoids sending 70k bytes to the server for every single email, which when you have thousands or tens of thousands of mails, is prohibitive.
SendGrid templating does not support this, but you can use a templating API like sendwithus to accomplish this on top of your SendGrid account. I believe sendwithus supports jinja conditionals, so you could do the following:
{% if variable %}
<h1>{{ variable }}</h1>
{% endif %}
Sendgrid supports conditional using Handlebar
{{#if user.profile.male}}
<p>Dear Sir</p>
{{else if user.profile.female}}
<p>Dear Madame</p>
{{else}}
<p> Dear Customer</p>
{{/if}}
from their documentation here https://sendgrid.com/docs/for-developers/sending-email/using-handlebars/#conditional-statements
Below handlebars can be used in Sendgrid dynamic templates:
Conditional statements:
{{#if variable}}
{{#unless variable}}
{{#greaterThan variable value}}
{{#lessThan variable value}}
{{#equals variable value}}
{{#notEquals variable value}}
{{#and variable1 variable2}}
{{#or variable1 variable2}}
Looping statements:
{{#each hash}}
Refer https://sendgrid.com/docs/for-developers/sending-email/using-handlebars/ for detailed information
SendGrid doesn't have true conditionals, but it does have Section Tags. With those, you can define a block of text at the message level (as opposed to the distinct recipient level of a Substitution Tag), and then call the appropriate section for the recipient as needed.
I Know this is old, but I had the same problem and I found a solution compatible with several email managers that maybe it's helpful for someone.
You can use substitution tags with the html comment symbols value in case you want to hide a section.
{%OPEN_COMMENT}
<h1>Whatever section you want to hide</h1>
{%CLOSE_COMMENT}
Replace tags with "" respectively if you want to hide the section. Replace them with empty strings in the other case.
I got the solution for keeping the field data when having error here.
But my form fields are in loop so when I use
{{form.varName_ofField}} it does not work.
Please help...
You can only access the form variable within a form object. For example:
{% form 'contact' %}
available here: {{form.email}}
{% endform %}
but not here: {{form.email}}
im pretty new to jQuery, and i dont know how to do that, and if it can be done without editing manually the plugin.
Assume to have a simply form like that:
<form action="page.php" method="post">
Name: <input type="text" name="Your name" id="contact-name" value="" />
Email: <input type="text" name="Your email" id="contact-email" value="" />
</form>
When you submit it, both in 'standard' way or with ajaxSubmit(), the values of the request take the label of the field name, so in the page.php i'll have:
$_POST['Your name'];
$_POST['Your email'];
Instead i'll like to label the submitted values with the id of the field:
$_POST['contact-name'];
$_POST['contact-email'];
Is there a way to do that with jquery and the ajaxsubmit() plugin?
And, maybe, there is a way to do it even with the normal usage of a form?
p.s: yes, i know, i could set the name and id attributes of the field both as 'contact-name', but how does two attributes that contain the same value be usefull?
According to the HTML spec, the browser should submit the name attribute, which does not need to be unique across elements.
Some server-side languages, such as Rails and PHP, take multiple elements with certain identical names and serialize them into data structures. For instance:
<input type="text" name="address[]" />
<input type="text" name="address[]" />
If the user types in 1 Infinite Loop in the first box and Suite 45 in the second box, PHP and Rails will show ["1 Infinite Loop", "Suite 45"] as the contents of the address parameter.
This is all related to the name attribute. On the other hand, the id attribute is designed to uniquely represent an element on the page. It can be referenced using CSS using #myId and in raw JavaScript using document.getElementById. Because it is unique, looking it up in JavaScript is very fast. In practice, you would use jQuery or another library, which would hide these details from you.
It is reasonably common for people to use the same attribute value for id and name, but the only one you need to care about for form submission is name. The jQuery Form Plugin emulates browser behavior extremely closely, so the same would apply to ajaxSubmit.
It's the way forms work in HTML.
Besides, Id's won't work for checkboxes and radio buttons, because you'll probably have several controls with the same name (but a different value), while an HTML element's id attribute has to be unique in your document.
If you really wanted, you could create a preprocessor javascript function that sets every form element's name to the id value, but that wouldn't be very smart IMHO.
var name = $("#contact-name").val();
var email = $("#contact-email").val();
$.post("page.php", { contact-name: name, contact-email: email } );
This will let you post the form with custom attributes.