2017-08-23 13:14
浏览 49

SilverStripe 3.6.1 - if / else_if语句未在模板中设置正确的字段

I'm trying to use an if/else_if statement in my homepage template to check which one of 2 fields have a value. Depending on which field has a value, a link is setup using the value of said variable.

However, as it stands, the setup I have does not work. I have an item with the ImageExternalLink field filled in but the statement seems to still think it's an internal link.

See below--this statement always sets the link as an Internal Link. It's almost like the else_if never is executed, although, I'm not sure why? I feel as if I am following the setup correctly based on the documentation.

div class="halfColumn">
   <% if $ImageLinkInternalURL.Link %>
     <a href="$ImageLinkInternalURL.Link">
         <p>Internal Link</p>
    <% else_if $ImageExternalLink %>
        <a href="$ImageExternalLink">
            <p>External Link</p>
    <% else %>
        <img class="dropShadow" src="$Image.URL" style="max-height: 220px;">
    <% end_if %>

For reference, here is the HomePageCallout.php file for reference, which is where the ImageLinkInternalURL and ImageExternalLink fields are created:


class HomePageCallout extends DataObject {

    private static $db = array(
        'SortOrder'     => 'Int',
        'ButtonText'    => 'varchar',
        'Header'        => 'varchar',
        'ImageExternalLink'  => 'varchar',
        'Description'   => 'HTMLText'

    static $default_sort = "SortOrder ASC";

    // One-to-one relationship with gallery page
    private static $has_one = array(
        'Image' => 'Image',
        'Page' => 'Page',
        'ImageLinkInternalURL' => 'SiteTree',

    // tidy up the CMS by not showing these fields
    public function getCMSFields() {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab("Root.Main", new NumericField("SortOrder"));
        $fields->addFieldToTab("Root.Main", new TextField("ImageExternalLink"), "SortOrder");

        return $fields;

    // Tell the datagrid what fields to show in the table
    public static $summary_fields = array(
        'ID' => 'ID',
        'Header' => 'Header',
        'Thumbnail' => 'Thumbnail',

    // 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(){
        return true;

    public function canView($member = NULL){
        return true;
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题