Javascript 如何在Kentico for email模板中每隔三个表单元格包装一行?

Javascript 如何在Kentico for email模板中每隔三个表单元格包装一行?,javascript,kentico,email-templates,Javascript,Kentico,Email Templates,如何使用Kentico电子邮件模板每隔三次用包装一次 我在jQuery中编写了以下代码,但不知道或不知道如何在Kentico中编写这个循环逻辑 var td=$(“#myTable tr td”);//全力以赴 td.每个(函数(i){//循环td 如果(i%3==0){//将td拆分为3的倍数 td.slice(i,i+3).wrapAll(“”)//将其包装在tr中 } }).parent('tr').unwrap(); 我希望使用Kentico使用相同的逻辑。您是否试图用Kentico宏

如何使用Kentico电子邮件模板每隔三次用
包装一次

我在jQuery中编写了以下代码,但不知道或不知道如何在Kentico中编写这个循环逻辑

var td=$(“#myTable tr td”);//全力以赴
td.每个(函数(i){//循环td
如果(i%3==0){//将td拆分为3的倍数
td.slice(i,i+3).wrapAll(“”)//将其包装在tr中
}
}).parent('tr').unwrap();

我希望使用Kentico使用相同的逻辑。

您是否试图用Kentico宏替换JS,该宏可用于电子邮件模板或电子邮件小部件

如果是这样的话,并且您有Kentico 11+,那么您可以转到电子邮件营销应用程序>电子邮件小部件,打开“最新文章”示例小部件,看看逻辑是如何工作的

下面是示例小部件的HTML/宏

{% /*
The Latest articles email widget dynamically obtains four latest articles from the Dancing Goat demo site at the time when the email issue is generated.
It achieves so by using macros that access pages with the given attributes.
*/ @%}

{% 
  articles = Documents["/Articles"]
               .CultureVersions["en-US"]
               .Children
                 .ClassNames("dancinggoat.article")
                 .OrderBy("DocumentPublishFrom DESC")
                 .TopN(4)
                 .WithAllData; 
return; 
#%}

<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellspacing="0" cellpadding="0" width="500">
<tr>
<td align="center" valign="top" width="500">
<![endif]-->
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:500px;">

{%
  i = 0;
  isFirstItemInRow = false;
  foreach (article in articles) { 
%}

{% 
    isFirstItemInRow = (Modulo(i, 2) == 0);
    articleUrl = UTMContent == String.Empty ? article.RelativeURL : article.RelativeURL + "?utm_content=" + UTMContent;
    articleTeaserUrl = GetAttachmentUrlByGUID(article.ArticleTeaser, "teaser", "teaser");
    articleLinkText = LinkText == String.Empty ? "Continue reading" : LinkText;
    return; 
%}

{%  if (isFirstItemInRow)  { %}
  <tr>
    <td align="center" valign="top" style="font-size:0; padding: 10px 0 15px 0" class="padding">
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellspacing="0" cellpadding="0" width="500">
<tr>
<![endif]-->
{% } /* END if */ #%}

<!--[if (gte mso 9)|(IE)]>
<td align="left" valign="top" width="240">
<![endif]-->
      <div style="display:inline-block; margin: 0 -2px; max-width:50%; min-width:240px; vertical-align:top; width:100%;" class="wrapper">
        <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="{% isFirstItemInRow ? "max-width:240px;" : "max-width:240px; float:right;" %}" class="wrapper">
          <tr>
            <td align="center" valign="top">
              <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td style="padding: 20px 0 30px 0;">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                      <tr>
                        <td align="center" valign="middle"><a href="{% articleUrl #%}" target="_blank"><img src="{% articleTeaserUrl #%}" width="240" height="130" style="display: block; color: #666666; font-family: Helvetica, arial, sans-serif; font-size: 13px; width: 240px; height: 130px;" alt="Fluid images" border="0" class="img-max"></a></td>
                      </tr>
                      <tr>
                        <td align="center" style="padding: 15px 0 0 0; font-family: Arial, sans-serif; color: #333333; font-size: 20px;">{% article.ArticleTitle #%}</td>
                      </tr>
                      <tr>
                        <td align="center" style="padding: 5px 0 0 0; font-family: Arial, sans-serif; color: #666666; font-size: 14px; line-height: 20px;">{% article.ArticleSummary #%}</td>
                      </tr>
                      <tr>
                        <td align="center" style="padding: 5px 0 0 0; font-family: Arial, sans-serif; color: #666666; font-size: 14px; line-height: 20px;"><a href="{% articleUrl #%}" target="_blank" style="color: #256F9C; text-decoration: none;">{% articleLinkText #%} &rarr;</a></td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>

            </td>
          </tr>
        </table>
      </div>
<!--[if (gte mso 9)|(IE)]>
</td>
<![endif]-->

{%  if (isFirstItemInRow)  { %}
<!--[if (gte mso 9)|(IE)]>
<td width="20" style="font-size: 1px;">&nbsp;</td>
<![endif]-->
{% } /* END if */ #%}      


{%  if (!isFirstItemInRow)  { %}
<!--[if (gte mso 9)|(IE)]>
</tr>
</table>
<![endif]-->                                    
</td>
</tr>
{% } /* END if */ #%} 

{% i++; return; %} 
{% } /* END foreach */ #%} 

</table>
{%/*
“最新文章”电子邮件小部件在生成电子邮件问题时从演示站点动态获取四篇最新文章。
它通过使用访问具有给定属性的页面的宏来实现这一点。
*/ @%}
{% 
条款=文件[“/条款”]
.cultureverions[“en-US”]
儿童
.类名(“dancinggoat.article”)
.OrderBy(“文档发布自描述”)
.TopN(4)
.所有数据;
返回;
#%}
{%
i=0;
isFirstItemInRow=false;
foreach(条款中的条款){
%}
{% 
isFirstItemInRow=(模(i,2)==0);
articleUrl=UTMContent==String.Empty?article.RelativeURL:article.RelativeURL+“?utm_content=“+UTMContent;
ArticleStratesUrl=GetAttachmentUrlByGUID(article.ArticleStrater,“摘要”,“摘要”);
articleLinkText=LinkText==String.Empty?“继续阅读”:LinkText;
返回;
%}
{%if(isFirstItemInRow){%}
{%}/*如果结束*/#%}
{%article.article标题#%}
{%article.ArticleSummary}
{%if(isFirstItemInRow){%}
{%}/*如果结束*/#%}
{%if(!isFirstItemInRow){%}
{%}/*如果结束*/#%}
{%i++;返回;%}
{%}/*结束foreach*/#%}

您是否试图用Kentico宏替换JS,该宏可用于电子邮件模板或电子邮件小部件

如果是这样的话,并且您有Kentico 11+,那么您可以转到电子邮件营销应用程序>电子邮件小部件,打开“最新文章”示例小部件,看看逻辑是如何工作的

下面是示例小部件的HTML/宏

{% /*
The Latest articles email widget dynamically obtains four latest articles from the Dancing Goat demo site at the time when the email issue is generated.
It achieves so by using macros that access pages with the given attributes.
*/ @%}

{% 
  articles = Documents["/Articles"]
               .CultureVersions["en-US"]
               .Children
                 .ClassNames("dancinggoat.article")
                 .OrderBy("DocumentPublishFrom DESC")
                 .TopN(4)
                 .WithAllData; 
return; 
#%}

<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellspacing="0" cellpadding="0" width="500">
<tr>
<td align="center" valign="top" width="500">
<![endif]-->
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:500px;">

{%
  i = 0;
  isFirstItemInRow = false;
  foreach (article in articles) { 
%}

{% 
    isFirstItemInRow = (Modulo(i, 2) == 0);
    articleUrl = UTMContent == String.Empty ? article.RelativeURL : article.RelativeURL + "?utm_content=" + UTMContent;
    articleTeaserUrl = GetAttachmentUrlByGUID(article.ArticleTeaser, "teaser", "teaser");
    articleLinkText = LinkText == String.Empty ? "Continue reading" : LinkText;
    return; 
%}

{%  if (isFirstItemInRow)  { %}
  <tr>
    <td align="center" valign="top" style="font-size:0; padding: 10px 0 15px 0" class="padding">
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellspacing="0" cellpadding="0" width="500">
<tr>
<![endif]-->
{% } /* END if */ #%}

<!--[if (gte mso 9)|(IE)]>
<td align="left" valign="top" width="240">
<![endif]-->
      <div style="display:inline-block; margin: 0 -2px; max-width:50%; min-width:240px; vertical-align:top; width:100%;" class="wrapper">
        <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="{% isFirstItemInRow ? "max-width:240px;" : "max-width:240px; float:right;" %}" class="wrapper">
          <tr>
            <td align="center" valign="top">
              <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td style="padding: 20px 0 30px 0;">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                      <tr>
                        <td align="center" valign="middle"><a href="{% articleUrl #%}" target="_blank"><img src="{% articleTeaserUrl #%}" width="240" height="130" style="display: block; color: #666666; font-family: Helvetica, arial, sans-serif; font-size: 13px; width: 240px; height: 130px;" alt="Fluid images" border="0" class="img-max"></a></td>
                      </tr>
                      <tr>
                        <td align="center" style="padding: 15px 0 0 0; font-family: Arial, sans-serif; color: #333333; font-size: 20px;">{% article.ArticleTitle #%}</td>
                      </tr>
                      <tr>
                        <td align="center" style="padding: 5px 0 0 0; font-family: Arial, sans-serif; color: #666666; font-size: 14px; line-height: 20px;">{% article.ArticleSummary #%}</td>
                      </tr>
                      <tr>
                        <td align="center" style="padding: 5px 0 0 0; font-family: Arial, sans-serif; color: #666666; font-size: 14px; line-height: 20px;"><a href="{% articleUrl #%}" target="_blank" style="color: #256F9C; text-decoration: none;">{% articleLinkText #%} &rarr;</a></td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>

            </td>
          </tr>
        </table>
      </div>
<!--[if (gte mso 9)|(IE)]>
</td>
<![endif]-->

{%  if (isFirstItemInRow)  { %}
<!--[if (gte mso 9)|(IE)]>
<td width="20" style="font-size: 1px;">&nbsp;</td>
<![endif]-->
{% } /* END if */ #%}      


{%  if (!isFirstItemInRow)  { %}
<!--[if (gte mso 9)|(IE)]>
</tr>
</table>
<![endif]-->                                    
</td>
</tr>
{% } /* END if */ #%} 

{% i++; return; %} 
{% } /* END foreach */ #%} 

</table>
{%/*
“最新文章”电子邮件小部件在生成电子邮件问题时从演示站点动态获取四篇最新文章。
它通过使用访问具有给定属性的页面的宏来实现这一点。
*/ @%}
{% 
条款=文件[“/条款”]
.cultureverions[“en-US”]
儿童
.类名(“dancinggoat.article”)
.OrderBy(“文档发布自描述”)
.TopN(4)
.所有数据;
返回;
#%}
{%
i=0;
isFirstItemInRow=false;
foreach(条款中的条款){
%}
{% 
isFirstItemInRow=(模(i,2)==0);
articleUrl=UTMContent==String.Empty?article.RelativeURL:article.RelativeURL+“?utm_content=“+UTMContent;
ArticleStratesUrl=GetAttachmentUrlByGUID(article.ArticleStrater,“摘要”,“摘要”);
articleLinkText=LinkText==String.Empty?“继续阅读”:LinkText;
返回;
%}
{%if(isFirstItemInRow){%}
{%}/*如果结束*/#%}
{%article.article标题#%}
{%article.ArticleSummary}
{%if(isFirstItemInRow){%}
{%}/*如果结束*/#%}
{%if(!isFirstItemInRow){%}
{%}/*如果结束*/#%}
{%i++;返回;%}
{%}/*结束foreach*/#%}

是否要在电子邮件正文中使用jQuery代码?在电子邮件中使用Javascript不是一个好的做法。请参阅发送包含JQuery脚本的html电子邮件,或者电子邮件消息中是否支持JavaScript?问题。或者你能澄清你的问题吗?我不想使用jQuery,因为它没有意义,你拥有什么,你想实现什么。我刚刚补充说,我想在Kentico Syntax中使用相同的jQuery逻辑。您想在电子邮件正文中使用jQuery代码吗?在电子邮件中使用Javascript不是一个好的做法。请参阅发送包含JQuery脚本的html电子邮件,或者电子邮件消息中是否支持JavaScript?问题。或者你能澄清你的问题吗?我不想使用jQuery,因为它没有意义,你拥有什么,你想实现什么。我刚刚补充说,我希望在Kentico SyntaxBundle中使用相同的jQuery逻辑,您能分享示例小部件的确切url吗?由于我找不到它的URL,它实际上位于电子邮件营销应用程序>电子邮件小部件中。如果你没有