Timber - WooCoommerce email templates - twig

Hi I'm using Timber and I need to modify the WooCommerce email templates and I've run into a problem:
If I want to use the classical twig template scheme and I place it correctly to the views/woocommerce/emails/customer-processing-order.twig it works (=the template is loaded), but I'm missing the template variables needed for actions, namely: $order, $sent_to_admin, $plain_text, $email
My question is simple - how to get these or how to load PHP email templates instead of twig files in this case?
UPDATE
I have found out that for WC emails the things are loading bit differently and having a separate woocommerce/emails folder works fine, but for the others doesn't.

Related

Is it possible to store handlebars templates in variables, and not in files?

There is a code written in typescript and node.js, the main purpose of it is sending emails. There are email text templates written in handlebars templating language, they are in a folder named "templates" together with the rest of the code.
I want to develop this by let the users edit the email templates. What was in the .handlebars files, now those texts are in the database (users can write it).
Until now, if a trigger happend and the code wanted to send an email, it used something.handlebars as an email text template. But now, the goal would be that the file named something.handlebars wouldn't exist anymore, and I would send what is stored in a given variable.
That variable is filled from the database (this is done), it is a string written in handlebars language. It would be important that handlebars should "process" the content of the variable before sending the email, because the text contains variable substitutions, formatting, etc...
I am not sure if this is possible with handlebars. When I configure handlebars in the code, I have to define a folder which contains the handlebars files, which tells me that I should have handlebars files, not variables which contains text written in handlebars syntax.
Is it possible with handlebars?
If so, how should I configure handlebars, and how could I do this?
If not, could you suggest me another email templating system, which is able to do these things (I mean, load template text from a variable, not a file)?
The current setup is working correctly (using .handlebars files), it sends the emails correctly. But as I see the config of the handlebars system, I guess that it is not possible to load the template text from a variable.
You're not sharing any code, so I have to guess at your implementation.
However, according to the documentation of handlebars.
You should be able to compile a template from a variable?

saving mail attachment with PowerAutomate to sharepoint corrupts the file

I am trying to build a flow based on the PowerAutomate template
Create Planner task and add attachments to SharePoint on new email
arrival
This template works fine, in that it saves all the mail attachments to my sharepoint. But it only shows the link to the last attachment in the task.
I have worked around it, by adding a string variable and appending all the sharepoint paths to this variable.
With my Flow, everything runs smoothly. But the stored files are about 10%- 20% bigger in size than the original and they turn out to be corrupted.
The only difference I can spot in the saving of the file is as follows:
Template section has "get attachment" and the according "body('get attachment'):
While my in my version I can only select "get attachment (V2)" and the corresponding "body('get attachment (V2)')
There is an option with V2 that allows or disallows chunking, but there is no effect on my filesize.
The other difference is, that I have my flow create a different folder based on the task ID, since there where errors, if the same name attachment came a second time. But I have tried my flow without the added folders and there is no difference in file size.
The original files:
and the corrupted files:
It makes no difference if I use the sharepoint link provided through the flow to my new planner task, or if I open the files directly within sharepoint. The result is an error.
Can anyone guess, why my flow seems to store something more within the file and thus corrupting it? I can provide the other parts of the flow in more detail too. Here is the overview of my custom flow:
I actually found the answer after rewriting it from scratch:
Using the old template had me looking for the wrong information when adding the attachment content to sharepoint. I had always searched for "body" which was used in the template and gave me this
But searching for attachment the dynamic content actually showed me the right pieces. I am not sure, if I missed it before, or if recoding a template hid them somehow. With the rewrite from scratch I found this:
So, to make a long story short: Use "Content Bytes" of the "Get_Attachment_(V2)" Method and everything works fine.

Loop over files in Twig

I am using Bolt CMS and want to have a table including all files of a specific directory on the server. How can this be achieved using a Twig template?
I have found that the following call works. The argument is a path in the files directory.
{% set files = app.filesystem.browse('SomeDirectory')[0] %}
This is not twig's task. This is something the controller layer should be responsible.
Get the list of files in your controller (though I'd probably create a model-layer class for this), and pass the list to your view, where it only needs to display it.

Style tags and Javascript in Template files

I'm looking through a project built by a foreign team. I am looking through some of the template files ending in ".ejs" and ".tmp", but from my limited knowledge, there is some bad convention here, can some of you confirm? Here are a few things I see on each template file:
1) The doctype, html tags and head are re-defined in each template file (stylesheet and JS files are linked on every one, but a different number of stylesheets and JS files linked depending on which template file it is).
2) there are Style Tags with a bunch of CSS in it, and Script tags with Javascript in it. So I'm guessing they did that because they only need those styles/JS in that particular template, but isn't it bad convention?
This is a node/express app I'm talking about. Is this a sign of bad convention/organization, or is it some sort of performance enhancement/convention I do not understand? Please advise me on this!

How to apply Dreamweaver templates on an existing site

I have an existing site in a path, and I've pointed the DreamWeaver site to it.
Under \templates there is a master.dwt file. But whenever I save this file, none of the html files which should make use of it change. What do I need to do to get DW to update the html files that make use of it? And how does DW know which files should be updated based on the template changing? Does it use an internal store or something because every time I copy the site to another machine, I'll need to link up all the pages to the relevant templates again.
I've tried going into Modify | Templates | Apply, but no templates are listed. I have a .dwt file in the path so why isn't it picking it up??
There's several possible issues in play here:
For Dreamweaver to properly recognize the existence of the template, the folder in the root of the site should be Templates and not templates.
Once Dreamweaver "sees" the Template properly you then need to make sure that the proper code is present in the child HTML files so Dreamweaver knows which files to update via the template. This code takes the form of HTML comments scattered throughout the page. You will always have the following line after the <html> tag:
<!-- InstanceBegin template="/Templates/TemplateName.dwt" codeOutsideHTMLIsLocked="false" -->
After that, editable regions are delineated with code that will look like this:
<!-- InstanceBeginEditable name="someregion" -->
stuff you can edit
<!-- InstanceEndEditable -->
Without the above, the child pages will not respond to the template.
Now for the real bad news. Unless the existing pages match up with the template exactly, you are going to have all kinds of problems getting the template to play nicely with the existing content. Doing Modify | Template | Apply Template to the page when the page is already fully formed will generate a dialog box that asks you map the content to the editable regions in the template. But if the rest of the design elements vary from what the template contains, Dreamweaver will preserve those tags alongside what the template will introduce which usually creates a ton of duplicated tags and broken layouts.
You would be FAR better off creating new, blank pages from the Dreamweaver Template and copy/pasting the contents into the editable area and then overwriting the "old" pages with the Save As command.
I just encountered this issue myself. I realize this original question was posted some time ago, but for anyone who might encounter this problem in the future, I am posting my solution.
If the only changes made to the template relate to one or more elements contained in an attached/linked file (such as a CSS style sheet or JS file), which changes Dreamweaver allows directly from the .dwt template itself, using the style boxes at the side/bottom, then Dreamweaver does not perceive any change to the actual .dwt file itself. If you want those changes to "take effect" and apply them to all pages, you might type a change to the .dwt file itself, click "save all" - undo the change and click "save all" again. This step is really not entirely necessary, as the changes to dependent files can be affected to the website by putting the dependent file to the website.
Also, Dreamweaver will apply changes to CSS/JS dependent files, across the board, but may continue to use a cache, until closed and reopened.

Resources