我正在使用domPDF在网站的某些页面上生成PDF
我遇到的问题是,它不允许我使用中继器值(通过任何循环),似乎并不想在创建PDF时生成它们。
如果我将中继器字段本身称为变量,它将返回“数组”,所以我认为可以通过某种方式使其工作。
似乎首先需要生成中继器,然后将其包含(也许作为变量?),但是我不确定如何做到这一点。
有人知道我如何使它工作吗?
这是我的ACF中继器代码:
<?php if( have_rows('team_contact_details') ): ?>
<div class="profile-item">
<ul class="list-contact">
<?php while( have_rows('team_contact_details') ): the_row(); ?>
<li>
<div class="list-contact-letter">
<?php the_sub_field("contact_label"); ?>
</div>
<div class="list-contact-detail">
<?php
if(get_sub_field('contact_link') == 'phone' ) {
echo '<a href="tel:' . get_sub_field("phone_number") . '">' . get_sub_field("phone_number") . '</a>';
} else if(get_sub_field('contact_link') == 'email' ) {
echo '<a href="mailto:' . get_sub_field("email_address") . '">' . get_sub_field("email_address") . '</a>';
}
?>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
这是我的domPDF代码:
//Print PDF
require_once get_template_directory() . '/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$content = '
<html>
<head></head>
<body>
<div class="person">
<img src="' . get_field('page_image') . '"/>
</div>
<h1>' . get_the_title() . '</h1>
<div class="pdf-label">' . get_field('team_academic') . '</div>
<div class="pdf-label">' . get_field('team_position') . '</div>
<<<< Attempting to put repeater values here as unordered list >>>>
</body>
</html>
';
// instantiate and use the dompdf class
$dompdf = new Dompdf(array(
'enable_remote' => true
)
);
$dompdf->loadHtml($content);
// (Optional) Setup the paper size and orientation
$dompdf->set_paper( 'letter' , 'portrait' );
// Render the HTML as PDF
$dompdf->render();
$doctitle = get_the_title();
$dompdf->stream($doctitle);
谢谢
答案 0 :(得分:0)
我明白了。仅供参考,方法如下:
if( have_rows('team_contact_details')) :
while(have_rows('team_contact_details')) : the_row();
$content .= '<h3>'. get_sub_field('contact_label') .'</h3>';
if(get_sub_field('contact_link') == 'phone') {
$content .= '<div>'. get_sub_field('phone_number') .'</div>';
} else {
$content .= '<div>'. get_sub_field('email_address') .'</div>';
}
endwhile;
endif;