Issue with Jade template losing proper indentation

I have created a jade email template that includes a mixin file with the header mixin. This mixin should be present in all emails. Although it is included properly, the issue arises due to the nesting level within it (3 levels deep), causing anything placed after the mixin to lose its intended nesting.

views/mixins/email.jade

mixin header(siteLogo)
  div(style='margin-bottom: 20px; border: 1px solid #ddd; padding: 20px; width: 50%; margin: 0 auto 20px;')
    div(style='text-align: center; border-bottom: 1px solid #EEE; padding-bottom: 10px;')
      img(src='#{siteLogo}', style='text-align: center;')

views/emails/forgot_password.jade:

include ../mixins/email

+header(siteLogo)
  p
    | Hi #{name},
  p
    | Welcome to the site!

The generated email html looks like this:

<div style="margin-bottom:20px;border:1px solid #ddd;padding:20px;width:50%;margin:0 auto 20px">
  <div style="text-align:center;border-bottom:1px solid #eee;padding-bottom:10px">
    <img src="path/to/image/logo" style="text-align:center">
  </div>
<p>Hi BobCobb</p>
<p>Welcome to the site!</p>

However, I want both of those paragraph tags to be inside the main <div> element as follows:

<div style="margin-bottom:20px;border:1px solid #ddd;padding:20px;width:50%;margin:0 auto 20px">
  <div style="text-align:center;border-bottom:1px solid #eee;padding-bottom:10px">
    <img src="path/to/image/logo" style="text-align:center">
  </div>
  <p>Hi BobCobb</p>
  <p>Welcome to the site!</p>
</div>

Answer №1

To provide a comprehensive response to the original query, it is crucial to indicate in the mixin where the block should be displayed.

views/mixins/email.jade

mixin header(siteLogo)
  div(style='margin-bottom: 20px; border: 1px solid #ddd; padding: 20px; width: 50%; margin: 0 auto 20px;')
    div(style='text-align: center; border-bottom: 1px solid #EEE; padding-bottom: 10px;')
      img(src='#{siteLogo}', style='text-align: center;')
    if block
      block

Answer №2

Jade is not the best choice for creating html emails. It is advisable to steer clear of using any web-based frameworks.

To understand why html email development differs from traditional web development, do some research.

When optimizing your code for html emails, consider the following structure:

<table width="50%" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #dddddd">
  <tr>
    <td align="center">
      <img alt="" src="path/to/image/logo" width="100" height="75" style="margin: 0; border: 0; padding: 0; display: block;">
    </td>
  </tr>
  <tr>
    <td style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #000000; padding:20px; border-top:1px solid #dddddd;">
      <p>Hi BobCobb</p>
      <p>Welcome to the site!</p>
    </td>
  </tr>
</table>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generate tables and rows dynamically

I am looking for guidance on dynamically creating a table and adding rows to it. I have successfully created a table with one row containing form fields, but I am unsure how to add additional rows. Any examples or suggestions on how this can be implemented ...

Looking to spice up your static HTML site? Dive into the world of Ruby on

I recently developed an app that features a static HTML webpage containing text and images, and now I'm interested in incorporating Ruby on Rails to explore its capabilities further. After creating a basic RoR application, I copied the HTML content f ...

Developing an editor

Currently, I am delving into the concept of object inheritance in JavaScript through a practical exercise where I am creating an online editor similar to the one I am currently using. However, I find myself slightly confused as I aim to utilize data-* att ...

Converting a Javascript object to an array results in an array with a length of

I am currently working on developing a website for online shopping, where users have the ability to add products from multiple stores to their cart and checkout, similar to the functionality of AliExpress. When users view their cart, the contents are disp ...

Invoking a function with a list of parameters

Just dipping my toes into the world of javascript here and I have a question. How do I call a function variable? Specifically, in the code snippet below, I want to trigger the add function of the fileupload control and pass custom data. Can anyone lend me ...

What is the process for turning off express logs on my node.js command line interface?

Recently, I've begun delving into the world of node.js and in an effort to improve my debugging practices, I've decided to move away from relying solely on console.log. Instead, I am exploring the use of debug("test message") for my debugging ...

Tips for placing a div within a curved div?

I've got a nested div situation, <div style="background-color: red; height: 100px; width: 100px; border-radius: 10px;" id="div1"> <div style="background-color: orange;" id="div2"> testing </div> </div ...

Emphasize the active page in the main menu

I'm struggling to use JavaScript and jQuery to highlight the current list item on my main menu. As a beginner in scripting, I am having trouble figuring out what's wrong with the code. Here is the code snippet that I have been working with. < ...

Activate only one option group at a time

<select name="location"> <optgroup label="West Coast"> <option value="1">Los Angeles</option> <option value="2">San Francisco</option> <option value="3">Seattle</option> &l ...

Unable to modify date or time in react-datetime package

Upon clicking the input box and entering a valid value, the input will either clear or be assigned a random date and time. This feature allows for the selection of a date or time using the mouse. Typing in the input will clear it or assign random values. ...

how can I use jQuery to disable clickable behavior in HTML anchor tags?

Here is the HTML code I am working with: (note -: I included j library on the top of page ) <div class="WIWC_T1"> <a href="javascript:void(0);" onClick="call_levelofcourse();popup('popUpDiv1')">Level of Course</a> </di ...

EJS selectively displaying certain elements from an object

This particular issue has been baffling me. I have been passing an object into an ejs template and when I output that object, everything appears as expected: { _id: 5504a5e7ff67ac473dd7655c, code: 'GB', name: 'United Kingdom', slug: & ...

What is causing my "mapDispatchToProps" to not recognize my action function?

Could someone please explain why I am receiving an error stating "getOnEvents() is not a function" when I call this.props.getOnEvents()? I can see the function in the props when I log it to the console, but for some reason, it throws an error when I try to ...

Choose all of the markers on the Google Map

for (i = 0; i < locations.length; i++) { var image = new google.maps.MarkerImage( 'logo.png', null, // size new google.maps.Point( 0, 0 ), // origin new google.maps.Point( 24, 48 ), // anchor (move to cente ...

Query to collect all user data using a WHERE clause

I recently started working with Firebase and have encountered an issue regarding the use of the 'where' clause. Here is a sample of the JSON data I'm dealing with: Users | |_____ John | |___ name: John Farmer | |___ searching ...

Array insertion is not supported by Node MSSQL

I am trying to insert multiple rows at once using an array of data. Here is how my array is structured: [ [ '1234' ], [ '5678' ], [ '9123' ]... ] And here is the query code I am using: const sql = require('mssql&a ...

What are the steps to effectively utilize an interface within a TypeScript file that contains its own internal import?

Currently, I am in the process of developing a React JavaScript project using WebStorm and attempting to enable type hinting for our IDEs (including VS Code) by utilizing TypeScript interfaces and JSDoc annotations. Our goal is to potentially transition to ...

Verification of radio selections

I have successfully implemented validation for the radio button. Now, I would like to add an alert box that asks "Are you sure you want to pick 'x'?" before proceeding with the code. If the user clicks cancel, they should return to the webpage. B ...

cursor misplaced following adjustments to mask

I have a phone number in the format 9999-9999. However, I would like it to be displayed as 99999-9999 when the user inputs an additional digit. The functionality is almost there, but the input is happening in the second-to-last spot instead of the last one ...

Resetting form after submitting an image in Meteor

In my Meteor App, I am using CFS for uploading files and everything is working fine except for one issue. When I try to upload another image, the previous uploaded image remains in the form, so I need a way to clear the form after submitting the new image. ...