1

我正在尝试在第三个菜单列表中的每一个上使用图像/徽标填充我的菜单项,请参见下面的示例。

在此处输入图像描述

我一直在使用 Silverstripe 来填充菜单项,下面是我到目前为止没有图像的代码。有人可以指出我如何在第三级菜单上插入图像/徽标的正确方向吗?

  // initialise plugins
  jQuery(function(){
     jQuery('ul.sf-menu').superfish();
  });

  </script>

  <ul class="sf-menu">
  <% control Menu(1) %>
     <li>
        <a href="#a">$MenuTitle</a>
         <% if Children %>
           <ul><% control Children %>
              <li>
                 <a href="#aa">$MenuTitle</a>

                  <% if Children %>
           <ul><% control Children %>
              <li>
                 <a href="#aa">$MenuTitle</a>
              </li>
              <% end_control %>

              </ul><% end_if %>
              </li>
              <% end_control %>

              </ul><% end_if %>

     <!--<li>
        <a href="#">menu item</a>
     </li>-->

        </li> <!--current-->
  <% end_control %><!--   <li>
        <a href="#">menu item</a>
     </li>   -->
  </ul> <!--sf-menu-->

多谢了。年代:)

下面的更新是我的 Page.php,我已将 $Image.SetSize(20,20) $MenuTitle 插入到我的第三级菜单中。但是,每次我尝试通过 CMS 插入图像时,CMS 中都会出现错误。对不起,我是新手,任何帮助将不胜感激。

<?php
class Page extends SiteTree {

public static $db = array(
);

public static $has_one = array(
        'MenuImage' => 'Image'
);

function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Images", new ImageField('MenuImage','Menu image'));

    return $fields;
}
}
     class Page_Controller extends ContentController {


public static $allowed_actions = array (
);

public function init() {
    parent::init();

    // Note: you should use SS template require tags inside your templates 
    // instead of putting Requirements calls here.  However these are 
    // included so that our older themes still work
    Requirements::themedCSS('layout'); 
    Requirements::themedCSS('typography'); 
    Requirements::themedCSS('form'); 
}
}

这是错误信息。

[用户错误] 无法运行查询:SELECT * FROM "Page" WHERE "ID" = 15 Table 'ss_show.page' 不存在 POST /Show/admin/EditForm/field/MenuImage/EditFileForm

C:\wamp\www\Show\sapphire\core\model\MySQLDatabase.php 中的第 525 行

4

3 回答 3

1

假设您的页面对象上有一个图像,您可以通过执行以下操作在模板中呈现它:

$MyImage.SetWidth(50) $MenuTitle

"$MyImage.SetWidth(50)" 将输出一个图片标签,图片的大小调整为 50px 宽。有关详细信息,请参阅SilverStripe 图像参考

于 2011-07-12T10:04:43.763 回答
0

I figured it out with soneone's help. Just in case others are in the same situation, it is because I didn't rebuild my database. Visit mysite.com/dev/build to rebuild the database. The code above in the update works after that. Thanks everyone! :)

于 2011-07-14T04:22:33.043 回答
0

如果您还没有菜单图像,请按照官方文档进行操作: http: //doc.silverstripe.org/sapphire/en/tutorials/2-extending-a-basic-site

于 2011-07-12T20:57:43.183 回答