【发布时间】:2020-08-02 09:11:34
【问题描述】:
所以我将 TailwindCSS 用于我正在开发的 WP 主题。
我在创建生产级主题文件时遇到了问题,因为根据我对问题的理解,purgecss 无法识别模板部件上使用的条件类。例如,假设我创建了一个名为“business-card.php”的模板部分,我将变量 type 传递给它(使用 set_query_var / get_query_var):
page-about.php
set_query_var('type', 'A');
get_template_part('template-parts/content/business', 'card');
set_query_var('type', 'B');
get_template_part('template-parts/content/business', 'card');
businesss-card.php
$type = get_query_var('type')
<div class="<?php echo type == 'A' ? 'text-color-A' : 'text-color-B' ?>">
--- insert some content here ---
</div>
所以会有两个 div,一个将有一个 text-color-A 类,另一个将有一个 text-color-B,两者都是使用配置文件创建的(而不是包含在基本的顺风主题中)。这在开发中很好——因为 tailwind 实际上确实从配置文件创建了实用程序颜色类。但由于某种原因,当它在生产中(即清除和缩小)时,它没有那些实用程序类——它们仅在模板部分用作条件类(而不是在任何其他文件中)。
【问题讨论】:
标签: wordpress-theming tailwind-css css-purge