Used mailJet module in node js
// template
Hello {{var:first_name:""}},
Welcome to Mailjet. This is an example of a templating
language message. This message contains variables and
nested loops (for .. endfor)! You could also embed
conditions (if .. else ..).
http://www.mailjet.com"}}">
Here is a link to click!
{% for rock_band in var:rock_bands %}
Title: {{ rock_band.name }}
{% for member in rock_band.members %}
Member name: {{ member }}
{% endfor %}
{% endfor %}
// data
{
"Subject": "test subject",
"MJ-TemplateID": "79501",
"MJ-TemplateLanguage": true,
"Recipients":[{ 'Email':"email here(valid email)"}],
"Vars": {
"first_name": "test name",
"rock_bands" : [{
"name": "test_name",
"members" : ['t','v']
}]
}
};
After successfully send email from node application,i checked MailJet dashboard but it's under BLOCKED status.
but template without conditional statements working fine.
Hope there's solution for it and thanks a ton.
The messages appear with status "blocked" when there is an error in the template. I tested the for loop provided and it worked fine for me so most likely there is another issue in the template syntax. Enable the template error management to receive a report about the error:
https://dev.mailjet.com/guides/#templates-error-management
If you still face troubles finding the error, contact Mailjet support as the issue would be related to the specific template.
Related
I've been scouring for more information about how to do this, but there seems to be little to no documentation help.
Essentially want I want to do is make a new template for the activation email so the link can start with localhost:3000 instead of localhost:8000 (I'm using Vue for the frontend post request that's why)
I managed to find this: https://github.com/sunscrapers/djoser/blob/master/djoser/templates/email/activation.html
but when I added it to my own project, the default Djoser template is still being used.
This is how my settings.py looks like:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
My activation URL which works if the 8000 is replaced by 3000 manually:
'ACTIVATION_URL': 'registration/activate/{uid}/{token}',
templates/email/activation.html:
{% block subject %}
{% blocktrans %}Account activation on {{ site_name }}{% endblocktrans %}
{% endblock subject %}
{% block text_body %}
{% blocktrans %}You're receiving this email becaus!!!!!!e you need to finish activation process on {{ site_name }}.{% endblocktrans %}
{% trans "Please go to the following page to activate account:" %}
{{ http }}://{{ localhost:3000 }}/{{ {% url 'registration/activate' uidb64=uid token=token %} }}
{% trans "Thanks for using our site!" %}
I suppose you need to override email.ActivationEmail, for example to core/email.py
from djoser import email
class ActivationEmail(email.ActivationEmail):
template_name = 'email/activation.html'
and add it to your settings.py
DJOSER = {
'EMAIL': {
'activation': 'core.email.ActivationEmail'
}
}
Here are emails which can be overwritten link
You can configure the DOMAIN and SITE_NAME in the settings.py file instead of changing the template.
Just put DOMAIN = ('localhost:3000') and SITE_NAME = ('YOUR_SITE_NAME')
DOMAIN = ('localhost:3000')
SITE_NAME = ('YOUR_SITE_NAME')
DJOSER = {
...
}
Source: https://stackoverflow.com/a/62586798/6568539 (I found that we don't need to use "config" as mentioned in this answer)
Without changing the Djoser email classes and settings.py, You can override the html templates in your project's template directory using the concepts here
You just simply have to create a new folder named email in your 'templates' folder and in it create html files with the exact names for the email templates that you would want to customize/override.
For example if you want to customize the password reset email, your custom file path should resemble this :
projectName/templates/email/password_reset.html
Here is a full list of all the Djoser email templates that you can customize
I found this closed thread and it did do the job of allowing me to render out a custom template. Might want to check this
the answer from Pavlo Naumenko works for me too so thanks a lot. But just a small note: I have to change the name of the file (I couldn't use "activation.html" on my own template). If I use it, django keeps sending the default template. Don't know why.
In case someone happens that too. I was using django 3.2.3 with djoser 2.1.0
it's working! I've just changed activation.html file in
~/.local/lib/python3.5/site-packages/djoser/templates/email
without any other changes
I'm trying to make a scroll on products in a given category for articles in shopware 6. I've managed to extend the product-detail html.twig file to add the next and previous on the page. The problem I'm facing is how to generate the URL links in a given category.
{% sw_extends '#storefront/page/product-detail/index.html.twig' %}
{% block base_content %}
« Previous
Next »
{{parent()}}
{% endblock %}
With the twig function seoUrl, you can generate links to other pages.
After the URL you can add query strings for the right pagination, see the example:
{{ seoUrl('frontend.navigation.page', { navigationId: 'ID' }) }}
How can I enable the aptoma twig-markdown extension? I have installed it using composer but when I use {% markdown %} in my twig file, I get an error message saying:
Unexpected "markdown" tag (expecting closing tag for the "block" tag
defined near line 8).
I had a look in the symfony documentation but was not able to find the solution.
Edit:
I tried to add the following code to services.yml but got another error:
twig.markdown:
class: Aptoma\Twig\Extension\MarkdownExtension
arguments: []
tags:
- { name: twig.extension }
Type error: Argument 1 passed to
Aptoma\Twig\Extension\MarkdownExtension::__construct() must be an
instance of Aptoma\Twig\Extension\MarkdownEngineInterface, none given
[...]
Upon request my .twig-file:
{% extends 'XYZBundle::layout.html.twig' %}
{% block title %}
{{ parent() }} – Eintrag anzeigen
{% endblock %}
{% block platform_body %}
<ul>
<li>
Back to the list
</li>
<li>
Edit
</li>
</ul>
<h1>{{ work.title }}</h1>
<div class="work-content">
{% markdown %}
{{ work.content }}
{% endmarkdown %}
</div>
{% endblock %}
According to the docs you need to install the markdown engine of your choice like:
composer require michelf/php-markdown
You need to create a service for the twig extension and the markdown engine, add the engine to the extension and register it as twig extension, f.e like this in your services.yml or config.yml:
services:
markdown.engine:
class: Aptoma\Twig\Extension\MarkdownEngine\MichelfMarkdownEngine
twig.markdown:
class: Aptoma\Twig\Extension\MarkdownExtension
arguments: ['#markdown.engine']
tags:
- { name: twig.extension }
Symfony will then automatically register it as twig extension through the usage of 'tags' or tagged services.
According to the new autowire system, you only have to declare the mardown engine implementing the Aptoma markdown engine interface.
Aptoma\Twig\Extension\MarkdownEngineInterface:
class: the markdown engine of your choice!
twig.extension.markdown:
class: Aptoma\Twig\Extension\MarkdownExtension
tags:
- { name: twig.extension }
If you do not change Aptoma\Twig\Extension\MarkdownEngineInterfaceby something like markdown.engine you do not need to declare arguments in your twig extension service declaration.
If you want to use the recommended markdown engine, install it via:
composer require michelf/php-markdown
Then, declare it:
Aptoma\Twig\Extension\MarkdownEngineInterface:
class: Aptoma\Twig\Extension\MarkdownEngine\MichelfMarkdownEngine
twig.extension.markdown:
class: Aptoma\Twig\Extension\MarkdownExtension
tags:
- { name: twig.extension }
You can see in vendor\aptoma subdirectories the available engine.
But you can use yours. It only have to implement MarkdownEngineInterface.
I'm trying to customize a specific widget, like in the documentation : http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field
The problem is that in this custom block, I need to use a variable from my actual template. I thought "blocks have access to variables from outer scopes", but apparently not in this case :
{% extends "CDASvBundle::layout.html.twig" %}
{% block _contact_activity1_widget %}
<select name="contact[activity1]">
{% for key, child_contact_categories in contact_categories_tab %}
<option value="{{key}}">{{child_contact_categories}}</option>
{% endfor %}
</select>
It's saying that contact_categories_tab is undefined, but outside of this block (in the normal content block for example), it works !
I tried something like :
{% use 'form_div_layout.html.twig' with contact_categories_tab as contact_categories_tab %}
But that doesn't either.. Though I'm not sure I understand if I have to use use and how !
I see one other solution that I haven't tried yet : put this customization in another template. But I don't really want to do that (few lines in a new template), there should be a way to do that in only ONE template ?!
Finally found the answer in a previous post :
Each symfony form type extents AbstractType class.
AbstactType class has method:
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->set('img_src', '120x100.jpg');
$view->set('my_variable', $foo);
}
You can create this method on your form type and next in your twig:
{{ asset(img_src) }}
Source : How to get entity or pass variable to Symfony2 twig form widget?
I am facing this problem.
I've got a page with an include of another like this:
index.html
{{ set pets = { pets : petsObject } }}
{{ include pets.html }}
petsObject is an object like this
petsObjects: [
{ name : "cat" },
{ name : "dog" }
]
When I try to render the page I get a blank page with only this:
[object Object]
I have no clue about what is going on :(
Thanks in advance!
Seems you'll need to use:
{% include pets.html with pets %}
According to docs for include:
Locally declared context variables are not passed to the included template by default.
It is also recommended for performance to use the only keyword after the included terms, like this:
{% include pets.html with pets only %}
Beyond that, it depends on the contents of pets.html, which you haven't included here. But, make sure that you're attempting to output the name:
{% for pet in pets %}
{{ pet.name }}
{% endfor %}
Or use a filter like json_encode() to format it:
{% for pet in pets %}
{{ pet|json_encode }}
{% endfor %}
Trying to output the Objects themselves will simply produce [object Object]:
new Object().toString() === "[object Object]"