PHP HREF Wrapping (Hosing .theme file)



希望用 $buttons_url 在 php 中包装一组div。进行了几次尝试,但继续清理整个文件。这是完整的函数调用。

function _get_single_page_content_offers() {
$content_offer = $collections = array();
$node = Drupal::routeMatch()->getParameter('node');
$langcode = Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
if($node->field_content_offers) {
$field_content_offers = $node->field_content_offers->getValue();
foreach($field_content_offers as $field) {
$collections[] = $field['target_id'];
}
$storage = Drupal::entityManager()->getStorage('node');
$resources = $storage->loadMultiple($collections);
$i = 1;
$c = count($resources);
foreach($resources as $resource_base) {
if ($resource_base->hasTranslation($langcode)) {
$resource = $resource_base->getTranslation($langcode);
} else {
$resource = $resource_base;
}
$title = $resource->title->value;
$type = ($resource->field_resource_type->entity) ? $resource->field_resource_type->entity->name->value : '';
$type = '';
if ($resource->field_resource_type->entity->hasTranslation($langcode))
{
$type = $resource->field_resource_type->entity->getTranslation($langcode)->name->value;
} else {
$type = $resource->field_resource_type->entity->name->value;
}
$content = ($resource->field_resource_content->value) ? $resource->field_resource_content->value : '';
$image = ($resource->field_resource_image->entity) ? $resource->field_resource_image->entity->url() : '';
$url = ($resource->field_resource_link->uri) ? $resource->field_resource_link->uri : $resource->url();
$buttons_url = $url;

要用 $buttons_url 包装的div

$content_offer[$i] = '        <div class="content-offer" data-mh="content-offer">';
$content_offer[$i] .= '         <img src="'.$image.'" alt="'.$title.'" class="img-responsive" />';
$content_offer[$i] .= '          <div class="info"> <span class="offer-type">'.$type.'</span>';
$content_offer[$i] .= '            <h4 class="h4">'.$title.'</h4>';
$content_offer[$i] .= '          </div>';
$content_offer[$i] .= '        </div>';
$i++;
}
}
return $content_offer;

}

我不确定你到底想要什么,但是:

$content_offer[$i]  = ' <a href="'.$button_url.'">';
$content_offer[$i] .= '        <div class="content-offer" data-mh="content-offer">';
$content_offer[$i] .= '         <img src="'.$image.'" alt="'.$title.'" class="img-responsive" />';
$content_offer[$i] .= '          <div class="info"> <span class="offer-type">'.$type.'</span>';
$content_offer[$i] .= '            <h4 class="h4">'.$title.'</h4>';
$content_offer[$i] .= '          </div>';
$content_offer[$i] .= '        </div>';
$content_offer[$i] .= ' </a>';

最新更新