这是我在扩展页面内使用HTML字符串的代码:
<?php
use DomDocument;
use Lullabot\AMP\AMP;
use Lullabot\AMP\Validate\Scope;
use common\helpers\StringHelper;
use yii\helpers\Html;
use yii\helpers\Url;
$amp = new AMP();
<body>
$html = $model->content;
$amp->loadHtml($html);
$amp_html = $amp->convertToAmpHtml();
if(isset($model['image'])){ ?>
<section class= "image-banner">
<amp-img src="<?= Url::to('@web/uploads/'.$model->image); ?>"
layout="responsive" width="900" height="467"></amp-img>
</section>
<?php } ?>
<section class="content-section">
<h1><?= $model->title;?></h1>
<?= $amp_html ?>
<div>
<?php if(Yii::$app->controller->id == "careers"){?>
<a href= "<?=Url::to(['/careers/'.$model->slug]) ?> ">
Fill application form.
</a>
<?php }?>
</div>
</section>
在浏览器中检查后的结果:
<a class="align-left" href="https://freelancercompany.com.np/admin/index.php?r=media%2Fview&slug=dg2">
<amp-img class="media-image media-9 align-left i-amphtml-element i-amphtml-layout-responsive i-amphtml-layout-size-defined" src="https://freelancercompany.com.np/uploads/2017/06/dg2.png" alt="dg2" width="1300" data-id="9" height="431" layout="responsive">
<i-amphtml-sizer style="display: block; padding-top: 33.1538%;"></i-amphtml-sizer></amp-img>
</a>
这里的问题是我无法将图像空白到位。正如您可以在amp-image标签上清楚地看到图像源。