私は内部リンクを各バナーに関連付けることができるサイトのローテーションバナー機能を更新しています画像。ただし、一部のバナーは外部のWebサイトのページにリンクする必要があります。そのためには、サイトツリーのリダイレクタページを参照し、リダイレクトを「別のウェブサイト」に設定しています。Silverstripe 3.5.1 - 内部リンクがリダイレクタページであるかどうかを確認し、そうであればリダイレクタページのリンクタイプを確認してください
ただし、外部リンクは新しいタブで開かれません。私は内部リンク値がリダイレクタのページタイプであるかどうかをチェックする方法を見つけようとしています。もしそうなら、そのリダイレクタページが外部リンクに設定されているかどうかを調べます。もしそうなら、 "target = _blank"を追加してください。
私はこれを試してみたが、運は - リンクはいつも私がリダイレクタページに設定したリンクの種類に関係なく、同じウィンドウで開きません。また、試してみました
<div class="Top-Banner clearfix" <% if $BackgroundImage %>style="background: url('$BackgroundImage.URL');"<% end_if %>>
<% if $InternalURL %>
<a href="$InternalURL.Link"
<% if $ClassName = 'RedirectorPage' %>
<% if $RedirectionType = 'External' %>
target="_blank"<% end_if %>
<% end_if %>>
<% end_if %>
<div id="Home-Banner-{$Pos}" class="Top-Banner-Inner clearfix" style="background: url('$Image.URL');background-size:cover !important;background-position:center center !important;">
<div class="Top-Banner-Content clearfix">
<h1 class="Top-Banner-Headline">$Header</h1>
<div class="Top-Banner-Sub-Text">
$Body
</div>
<div class="Top-Banner-Buttons clearfix">
<input type="button" value="Patient Portal - Login" onmouseover="this.style.background='#$PatientPortalBtnHoverColor'" onmouseout="this.style.background='#$PatientPortalBtnColor'" style="background-color: #$PatientPortalBtnColor;" onclick="window.location.href='$PatientPortalInternalURL.Link'" />
<input type="button" value="Learn More" onmouseover="this.style.background='#$LearnMoreBtnHoverColor'" onmouseout="this.style.background='#$LearnMoreBtnColor'" style="background-color: #$LearnMoreBtnColor;" onclick="window.location.href='$LearnMoreInternalURL.Link'" />
</div>
</div>
</div>
<% if $InternalURL %>
</a>
<% end_if %>
</div>
:
<% if $InternalURL %>
<a href="$InternalURL.Link"
<% if $RedirectionType='External' %>
target="_blank"<% end_if %>>
<% end_if %>
それはRedirectorPageとしてページタイプを認識しないように動作
<% if $InternalURL %>
<a href="$InternalURL.Link"
<% if $InternalURL.ClassName = 'RedirectorPage' %>
target="_blank"
<% end_if %>>
<% end_if %>
、:
もこれを試してみましたND私は動作しませんターゲット=「_ブランク」とそれ以外のものは何でも、しかし$ RedirectionType =「外部」と一緒にそれを使用して設定することができます
<% if $InternalURL %>
<a href="$InternalURL.Link"
<% if $InternalURL.ClassName = 'RedirectorPage' %>
<% if $RedirectionType = 'Internal' %>target="_blank"<% end_if %>
<% end_if %>>
<% end_if %>
を私はリダイレクタのページがある場合にも、チェックできるようにする必要があります外部リンクに設定する - リンクがリダイレクタページからのものであるため、単に新しいウィンドウでリンクを開くことはできません。コンテンツマネージャは、内部リンクを使用し、リンクがクリックされたときに同じページに留まることができます。ここで
はRotatorImageデータオブジェクトのためのコードです:<?php
class RotatorImage extends DataObject {
private static $db = array(
'SortOrder' => 'Int',
'Header' => 'varchar',
'Body' => 'HTMLText',
);
// One-to-one relationship with gallery page
private static $has_one = array(
'Image' => 'Image',
'BackgroundImage' => 'Image',
'Page' => 'Page',
'InternalURL' => 'SiteTree',
);
// tidy up the CMS by not showing these fields
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab("Root.Main","PageID");
$fields->removeFieldFromTab("Root.Main","SortOrder");
$fields->addFieldToTab('Root.Main', new TreeDropdownField("InternalURLID","Banner Link","SiteTree"));
return $fields;
}
// Tell the datagrid what fields to show in the table
private static $summary_fields = array(
'ID' => 'ID',
'Title' => 'Title',
'Thumbnail' => 'Thumbnail',
'InternalURLID' => 'Internal URL',
);
// this function creates the thumnail for the summary fields to use
public function getThumbnail() {
return $this->Image()->CMSThumbnail();
}
public function canEdit($member=null) {
return true;
}
public function canDelete($member=null) {
return true;
}
public function canCreate($member=null){
return true;
}
public function canPublish($member=null){
return true;
}
public function canView($member=null){
return true;
}
}
「InternalURL」とは何ですか?それはページとhas_oneの関係ですか? –