Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Email templates structure

Hi community,

I'm wondering if anyone can give me some guidance on what the deal is with email templates.

I know I can override them in my themes, but I'm wondering what the deal is with the nice source template in applications/dashboard/views/email/src. Is it nothing? Is it something that can be compiled into a proper template? I can't seem to find any information on it.

Tagged:

Comments

  • I don't know much about that, only that statement from @beckyvb
    But I cannot find a place where that file gets compiled...

  • @jamesinc said:
    Hi community,

    I'm wondering if anyone can give me some guidance on what the deal is with email templates.

    I know I can override them in my themes, but I'm wondering what the deal is with the nice source template in applications/dashboard/views/email/src. Is it nothing? Is it something that can be compiled into a proper template? I can't seem to find any information on it.

    Try this https://open.vanillaforums.com/discussion/23562/tutorial-how-to-customize-your-emails

  • @vrijvlinder while generally useful, that's not the sort of information I'm after. In this case I'm specifically wondering if there is some way to use the nice src files for (new to Vanilla 2.3) HTML e-mail templates. Maybe a build tool that @beckyvb has that isn't distributed, or something along those lines.

  • edited February 2017

    Why can't you just clone that email-basic.php or the email-basic.tpl and put it in your views folder for your theme ?

  • I can, and have, cloned e-mail-basic.tpl, and that works, but the tpl file is full of inline styles and is not particularly nice to read, and there's this nice src/email-basic.php sitting there in the distributed version of Vanilla 2.3, and I want to know if there's some better way to modify the templates that doesn't involve going through inline CSS.

    Or put it another way, I want to know what src/email-basic.php is all about. Why is it there? Is there some way to use it? Is there a tool that can compile it into an inline-styled tpl file?

  • edited February 2017

    A tpl file uses Smarty and the php one does not. You could use either one, I think. But it would be easier to edit the style using the definitions to add the inline css as in the link I gave you.

    You can also beautify the unreadable file .... https://ctrlq.org/beautifier/

    Just copy the code enter it in the box and click beautify. It will make it look nice and orderly.

  • if there's some better way to modify the templates that doesn't involve going through inline CSS.

    You could write a style sheet for it and then add the meta tag to call the css file in the email tpl or php...

  • @vrijvlinder said:
    You could write a style sheet for it and then add the meta tag to call the css file in the email tpl or php...

    I think in external CSS assets are problematic for many e-mail clients. I'll see if the non-Smarty template works when put into my themes directories. I could always embed the CSS using PHP anyway.

    But to keep the thread on-topic, specifically the question I am looking for an answer to is why does src/email-basic.php exist.

    @vrijvlinder said:
    it would be easier to edit the style using the definitions to add the inline css as in the link I gave you.

    That's what I would do if I wanted to modify specific e-mail message bodies, but in this instance I'm looking at the overall template.

    I think the conclusion I'm coming to is that the easiest thing to do is just bin the default template entirely and write a new one in my theme directories.

  • edited February 2017

    why does src/email-basic.php exist.

    Because that is the basis for the tpl file. The same way that the default.master.php used to be the main template until they started using the smarty tpl template. But it all is still based on php and php templates still work well.

    If you look at the Smarty folder in the vendors folder. You will see that there is where the php is and then in the tpl it uses {} to call the php but as a smarty code. It's a way to simplify php.

    You can use either one. the tpl or the php template. I prefer working with php. But that is me.

    That's what I would do if I wanted to modify specific e-mail message bodies, but in this instance I'm looking at the overall template.

    No, that would affect all emails. Not just one. You can add html and css inside the definitions. It would be a place where it could be appropriate. More so than cloning the entire template.

    I think the conclusion I'm coming to is that the easiest thing to do is just bin the default template entirely and write a new one in my theme directories.

    You can do that too.

  • jamesincjamesinc ✭✭
    edited February 2017

    No, that would affect all emails. Not just one. You can add html and css inside the definitions. It would be a place where it could be appropriate. More so than cloning the entire template.

    Yes, if I rewrote all the email body definitions to reference a base template string, sure, it would affect all of them. But then that template would end up being embedded inside of the Smarty HTML Email template, so I'd still have to modify that template (or disable the new 2.3 HTML email feature, which kind of defeats the purpose of it being added to Vanilla in the first place).

    Because that is the basis for the tpl file.

    Okay, and that's what I suspected all along, but how is the php file turned into the Smarty tpl file? Or are the files just loosely based off one another, and each is hand-edited (by Vanilla core devs) separately? Is it something that just gets handled when the dist code is built by Composer? I don't know. Either they're just separate files, or there's some magic occurring on the vanilla dev side. That's what I am trying to find out.

  • how is the php file turned into the Smarty tpl file

    I looked into this , and the answer lies in the Smarty plugin folder in the library/vendors folder and smarty folder. It is all PHP files. Smarty compiles the PHP into shortcuts if you will...

    Or are the files just loosely based off one another

    No, files are not loose. They are predetermined for a reason. You should look into http://www.smarty.net/ and then understand the work flow.

    or there's some magic

    yea but it's not this, this is concrete and purposeful and has to do with the layout and style. Not function.

  • Cool, I'll dig more into Smarty's compiler then to understand how it is handling this. Thanks for all the help!

  • If you compare the php and the tpl file you will see that there are two main differences:
    1. the php file has a "wrong" notation for php control structures but that is compiled to correct Smarty control structures
    2. while the css is an inline block in the php, it is split into style attributes in the Smarty template

    Vanilla uses grunt to compile all the assets. I know there are grunt tasks to inline css like you can see it in the email template, but I haven't found a script which does this here. But I would bet there is one...

    Maybe you should simply add a question to the GitHub link from above and I bet @beckyvb will give you an answer quickly!

Sign In or Register to comment.