2017-08-16 27 views
0

打算在php中用$ buttons_url包裝一組div。做了幾次嘗試,但保持整個文件。這是整個函數調用。PHP HREF Wrapping(Hosing .theme文件)

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; 

的div $ 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; 

}

+0

可以添加更多的代碼嗎?這是不明確的。 – Fky

+0

你明白了。讓我知道這是否有所幫助。 – Zybert

回答

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