I want to send a condition-based template in AWS SES Template.
i.e
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
Can anyone please tell me How I can achieve this in AWS SES Template?
My goal is to send templates part on a condition based.
I think this is what you're looking for:
{{#if User.UserAttributes.FirstName.[0]}}
Hello {{User.UserAttributes.FirstName.[0]}},
{{else}}
Hello,
{{/if}}
Check https://docs.aws.amazon.com/pinpoint/latest/userguide/message-template-helpers.html for more info, examples and alternative conditional statements.
Related
I am using django with django-channels and htmx.
In certain cases, my django views will send an SSE event to a user subscribed to the relevant channel, like a notification for example. Some of those events (depending on event name) needs to trigger a modal pop-up (like a rating modal after an e-commerce order or service completes).
I have implemented the requirements of the server-side event and data generation. I want to use the htmx sse extension on the frontend (django template).
My problem is, I want to get an event, let's say order_complete, and use that to trigger an hx-get call to a particular url which will be sent by the sse event. That hx-get's response will then be placed in the placeholder where modal view logic exists. I can get the event and trigger the get request as described in the htmx sse extension docs, but I don't know how to get the url to put in the hx-get.
I have very little knowledge of JavaScript and not all that much more on htmx. I've looked at out of band swaps but I'm not sure if that's what I need.
I'd appreciate any opinion or suggestions for proceeding including a non-htmx solution if it's better performing or easier.
Thank you.
You can append parameters to a (fixed) url.
In a client side javascript handle the sseMessage event.
document.body.addEventListener('htmx:sseMessage', function (evt) {
//* check if this event is the one you want to use
if (evt.detail.type !== "order_complete") {
return;
}
//* If a JSON string was sent, leave it as it is
//evt.detail.elt.setAttribute("hx-vals", evt.detail.data);
//* if not
var msg = {};
msg.orderId = evt.detail.data;
evt.detail.elt.setAttribute("hx-vals", JSON.stringify(msg));
});
see https://htmx.org/attributes/hx-vals/
resulting url if evt.detail.data was 123:
/orders/showmodal?orderId=123
the html:
<div hx-ext="sse" sse-connect="/sse-something">
<div hx-get="/orders/showmodal"
hx-trigger="sse:order_complete"
hx-swap="innerHTML"
hx-target="#idModalPlaceholder">
</div>
</div>
Update
You can also use an event listener just for order_complete.
document.body.addEventListener('sse:order_complete', function (evt) {
//* If a JSON string was sent, leave it as it is
//evt.detail.elt.setAttribute("hx-vals", evt.detail.data);
//* if not
var msg = {};
msg.orderId = evt.detail.data;
evt.detail.elt.setAttribute("hx-vals", JSON.stringify(msg));
});
Trying to work out accept.js to replace a depreciated method for authorize.net payments. Not doing anything gcomplicated, but can't get past the authentication failed message when using the sandbox
Logging into the sandbox account to generate keys … they're named slightly differently than the code samples. So I MAY BE AN IDIOT.
OK, apiLoginID - obvious …
Code below calls for data-clientKey. Not 100% sure which of the two below that actually is. I've tried both. Same error with both.
API Login ID : 4CLLpD------
Transaction Key : 9628s6xCSh------
Key : ------A4D932A4AFED546DE55E4D04C16CA66549915AFDC4FBA3A1665E271A2FB48A7A34394843A47BC170FFB4A5B99EDD17B75D99942E4E7F7133C2E1------
<script type="text/javascript"
src="https://jstest.authorize.net/v3/AcceptUI.js"
charset="utf-8">
</script>
<form id="paymentForm"
method="POST"
action="mysite.com/beta-account/order-receipt.php" >
<input type="hidden" name="dataValue" id="dataValue" />
<input type="hidden" name="dataDescriptor" id="dataDescriptor" />
<button type="button"
class="AcceptUI btn-success btn-lg"
data-billingAddressOptions='{"show":true, "required":false}'
data-apiLoginID="4CLLpDX----"
data-clientKey="9628s6xCShc-----"
data-acceptUIFormBtnTxt="Submit"
data-acceptUIFormHeaderTxt="Card Information"
data-responseHandler="responseHandler">Pay
</button>
</form>
<script type="text/javascript">
function responseHandler(response) {
if (response.messages.resultCode === "Error") {
var i = 0;
while (i < response.messages.message.length) {
console.log(
response.messages.message[i].code + ": " +
response.messages.message[i].text
);
i = i + 1;
}
} else {
paymentFormUpdate(response.opaqueData);
}
}
function paymentFormUpdate(opaqueData) {
document.getElementById("dataDescriptor").value = opaqueData.dataDescriptor;
document.getElementById("dataValue").value = opaqueData.dataValue;
document.getElementById("paymentForm").submit();
}
</script>
Right now, there's not really anything on the order-receipt.php page. I'm just trying to get the post to make it that far and show me a dump of everything that post to the page, so even once I get this working, I've still got a ways to go.
When I go to the payment page, hit the "Pay" button, fill out the credit card form, hit "submit" … it doesn't go anywhere at all. It stays on the page and the console reports: "E_WC_21: User authentication failed due to invalid authentication values."
This has turned into one more frustrating thing after pulling over half my hair out over authorize.net's documentation of what I need to do about the MD5 end-of-life … of which I never could get anything to work to replace the SIM relay-response method that was being used. response.js seems fairly simple as a replacement, and I'm stuck here too.
What do I try next?
OK, I think I found the problem …
There's a difference between the API Login ID, the Transaction Key, and the Client Key.
That's not immediately obvious in some of the docs ….
For getting the data-clientKey, you should go to this place. Please see the attach screenshot.
Screenshot
I just want to know, is there some way I can achieve the below purpose.
<button class="{{unless publishable "button-disabled"}}" {{if publishable (action "publish")}}>Publish</button>
Of course, it can be done in action method. I just think it could keep code drier if it can be done in template.
NOTE:
I know the code above will not work. It's only for purpose illustration.
I know button can use disabled attribute to achieve this. In my original work, it is actually a <a/> which doesn't have disabled. I need to keep it as <a/> tag for css purpose.
I wish to keep the button in page no matter it is disabled or not. This is kind of web page convention. In that case, user will know that he must missing something when the button is disabled.
It is possible using {{mut}} in combination with {{action}} helper:
<button {{action (if publishable 'publish' (action (mut undefProp)))}}>Publish</button>
Working demo.
You can read more about this specific use case (mut converts to function) in this blog post.
Explanation:
We use action helper and action which we pass to that helper will be computed - based on if condition.
If condition evaluates to true we return 'publish' which is simply action name.
If condition evaluates to false then we pass action which does nothing - we use something like workaround: (action (mut undefProp)).
Been scratching my head on this, so here's the simplest way to view it - I'm using this:
Template.today.rendered = function() {
console.log(this.firstNode.children.length);
};
Simply to try and get the count of items that are supposedly rendered. The template looks like:
<template name="today">
<div class="todaySlider">
{{#each dayOfWeek}}
{{> singleDay}}
{{/each}}
</div>
</template>
and if it's of any importance, singleDay looks like:
<template name="singleDay">
<div class="day {{isCurrent}}">
<h2 class="date">{{date}}</h2>
{{#each items}}
{{> item }}
{{/each}}
</div>
</template>
I'm trying to wait for all the "singleDays" to render, however that count I'm logging is usually different on refresh. I'll get anything from 0 to the correct value, and I don't understand why. This seems to be the right place to call it, I fear that maybe the double "each" is too slow?
I've tried timers (which I honestly shouldn't) and even DOM Mutation Observers (which seem like overkill) but surely there is a pure Meteor approach to this, any ideas?
Template.rendered happens when the template is rendered, but that doesn't mean there'll be any data in it.
I'm pretty sure you'll need to do this inside a helper.
each helpers don't have to return cursors, they can also return an array. If the number of "singleDays" is short, you could send an array to the template instead of a cursor. It's kind of ugly, and there might be a better way to do this, but I think this will work.
Template.today.helpers({
dayOfWeek: function() {
var days = DaysCollection.find({}).fetch();
if (days[days.length - 1]) days[days.length - 1].isLast = true;
return days;
}
});
I assume {{isCurrent}} is where you add the extra class that you're talking about. If so, just have the isCurrent helper look for this.isLast to be true.
Seems like what is happening here is that the template is being rendered before the Mongo collection is sent to the client. To be more specific, meteor renders your template as fast as possible, which means that it has no concept of 'waiting' for any data to be sent from the server to the client. Therefore, if you place anything indirectly regarding database queries inside of a non-reactive call (Template.rendered), then it will execute with the data as undefined.
I'm assuming your dayOfWeek helper looks something like this:
Template.today.helpers({
daysOfWeek: function () {
var today = CollectionName.findOne();
return today.daysOfWeek;
}
})
(Or maybe you are using the router to pass the day directly to the template)
Either way, within your router you need to wait for the Mongo collection item to be sent to the client before any rendering takes place. If you are using Iron-Router, you simply have to 'wait' for your data/subscription.
More information can be found here: https://github.com/iron-meteor/iron-router/blob/devel/Guide.md#wait-and-ready
If you are still using autopublish, then you can replace the subscription with your database query.
I got a code like this in joomla backend.
<td class="center"><?php echo JHtml::_('jgrid.published', $item->published, $i, 'products.', TRUE, 'cb'); ?></td>
The publish function work correctly sending me to my controller products and method publish. However, the unpublish was not correct it send me to publish method instead of unpublish method, even though the anchor tag still show correctly like this <a class="jgrid" href="javascript:void(0);" onclick="return listItemTask('cb7','products.unpublish')" title="Unpublish Item">
anyone got any idea about it?
This is a really really old question, but I just came across the same problem myself.
It looks like they are saving space by using the same method (which you pointed out) "publish" for both publish and unpublish functionality.
The problem is that in the method it checks how to set the state, but does so based on the "task" which for some reason does not strip the context of the controller out of the post data. So... instead of looking for...
if( $post['task'] == 'unpublish' ){
...you should be looking for...
public function publish(){
$post = JRequest::get('post');
if( $post['task'] == 'items.unpublish'){
$state = 0;
}else{
$state = 1;
}
Notice how the task we are looking for is items.unpublish (items being your controller) instead of just unpublish.
I know this is probably way to late, but hopefully it helps someone.