1

I created a newsletter with the module "Simplenews". I also created a custom template for my newsletter :

  <table border="0" cellspacing="0" cellpadding="0" width="100%">
    <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>
    <tr>
      <td align="center">
       <a href="<?php print $node_url; ?>" target="_blank">
        <table class="deviceWidth" border="0" cellpadding="0" cellspacing="0" width="580" align="center" style="border: 1px solid #ddd;">
          <tr>
            <td>
              <table class="deviceWidth" border="0" cellpadding="0" cellspacing="0" width="280" align="left">
                <tr>
                  <td align="center">
                    <?php print render($content['field_image']); ?>
                  </td>
                </tr>
              </table>
              <table class="deviceWidth" border="0" cellpadding="0" cellspacing="0" width="280" align="right">
                <tr>
                  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #2b9900; font-size: 16px; font-weight: bold; text-decoration: none;">
                    <?php print render($content['title']); ?>
                  </td>
                </tr>
                <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>
                <tr>
                  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #313a42; line-height: 20px; text-align: justify;">
                    <?php print render($content['body']); ?>
                  </td>
                </tr>
                <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>
                <tr>
                  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
                    <?php print render($content['product:commerce_price']); ?>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
       </a>
      </td>
    </tr>
    <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>

I use the module "Commerce Price Savings Formatter" to view the original price, discounted prices and the discount percentage. Prices are displayed correctly on my site and the mail client, except on gmail that removes all the CSS class (even inline style). The next line problem <?php print render($content['product:commerce_price']); ?> because it displays the entire price (original discount and percentage). I want to apply a style to the original price, a different style to discounted prices and a different style to the club proucentage.

I think we should create 3 cell. But I do not know what to put in the line :

    <tr>
      <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
         <?php ?????????; ?>
      </td>

      <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
         <?php ?????????; ?>
      </td>

      <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
         <?php ?????????; ?>
      </td>
   </tr>

How to do this ?

enter image description here

enter image description here

  <table border="0" cellspacing="0" cellpadding="0" width="100%">
    <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>
    <tr>
      <td align="center">
       <a href="<?php print $node_url; ?>" target="_blank">
        <table class="deviceWidth" border="0" cellpadding="0" cellspacing="0" width="580" align="center" style="border: 1px solid #ddd;">
          <tr>
            <td>
              <table class="deviceWidth" border="0" cellpadding="0" cellspacing="0" width="280" align="left">
                <tr>
                  <td align="center">
                    <?php print render($content['field_image']); ?>
                  </td>
                </tr>
              </table>
              <table class="deviceWidth" border="0" cellpadding="0" cellspacing="0" width="280" align="right">
                <tr>
                  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #2b9900; font-size: 16px; font-weight: bold; text-decoration: none;">
                    <?php print render($content['title']); ?>
                  </td>
                </tr>
                <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>
                <tr>
                  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #313a42; line-height: 20px; text-align: justify;">
                    <?php print render($content['body']); ?>
                  </td>
                </tr>
                <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>
                <?php foreach($content['product:commerce_price'] as $commerce_price): ?>
                <?php foreach($commerce_price['#prices'] as $price): ?>
                <tr><td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;"><?php print $price['#markup']; ?></td></tr>
                <?php endforeach; ?>
                <?php endforeach; ?>
              </table>
            </td>
          </tr>
        </table>
       </a>
      </td>
    </tr>
    <tr><td height="5" style="font-family: 0px; line-height: 0px;">&nbsp;</td></tr>
  </table>

1 Answer 1

0

You have to find out which keys that hold the values in question within $content['product:commerce_price']. Then use those in your template. For example:

At the very bottom of your custom template append:

<?php drupal_set_message('<pre>'.print_r($content['product:commerce_price'],1).'</pre>'); ?>

Clear cahe, run your custom template (e.g. by visiting the page/url where the custom template used) and find keys that hold original, discount and percentage value.

After you found those keys, respectively use them in your "I think we should create 3 cell. But I do not know what to put in the line : <?php ?????????; ?>". Then remove the drupal_set_message line above.

Further reading:

https://www.drupal.org/documentation/theme
https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_set_message/7.x
http://php.net/manual/en/language.types.array.php#example-101

HTH

UPDATE

From what I can see from your update, replace your

<tr>
  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
    <?php print render($content['product:commerce_price']); ?>
  </td>
</tr>

with

<?php foreach($content['product:commerce_price'] as $commerce_price): ?>
  <?php foreach($commerce_price['#prices'] as $price): ?>
    <tr><td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;"><?php print $price['#markup']; ?></td></tr>
  <?php endforeach; ?>
<?php endforeach; ?>

UPDATE 2

Replace the above with:

<tr>
  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
    <?php print $content['product:commerce_price'][0]['#prices']['list']['#markup']; ?>
  </td>

  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
    <?php print $content['product:commerce_price'][0]['#prices']['price']['#markup']; ?>
  </td>

  <td valign="top" align="center" style="font-family: Arial, Helvetica, sans-serif; color: #000000; font-size: 20px; font-weight: bold; text-decoration: none;">
    <?php print $content['product:commerce_price'][0]['#prices']['savings']['#markup']; ?>
  </td>
</tr>
2
  • thank you for your reply. What file find these variable?
    – user61056
    May 29, 2016 at 16:08
  • You can use node.tpl.php. May 29, 2016 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.