PHP HREF Wrapping(Hosing .theme文件)

时间:2017-08-16 15:29:48

标签: php drupal

想用$ 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

包装
$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;

}

1 个答案:

答案 0 :(得分:0)

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

$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>';