Within a Tridion GUI Extension, how to add an icon to the context-menu?

帅比萌擦擦* 提交于 2019-12-05 09:55:50

Yes the icon is 16 x 16.

I've always done it using CSS, I hope this explanation makes sense:

1) In your editor.config, you specify the css file and other resources you need

<cfg:groups>
  <cfg:group name="PowerTools.Resources.Base" merge="always">
    <cfg:fileset>
        <cfg:file type="style">/PowerTools/Client/Shared/Theme/styles.css</cfg:file>

2) When you configure the context menu, you have the ID attribute in the ContextMenuItem (shown below as PT_PagePublisher)

<ext:contextmenus>
  <ext:add>
    <ext:extension name="PowerToolsContextMenu" assignid="PowerToolsContextMenu" insertbefore="cm_refresh">
      <ext:menudeclaration externaldefinition="">
        <cmenu:ContextMenuItem id="PowerToolsMenuGroup" name="Power Tools">
          <cmenu:ContextMenuItem id="PT_PagePublisher" name="Page Publisher" command="PT_PagePublisher"/>

3) In your CSS file you'll have something like:

.PT_PagePublisher .image {background-image:url({ThemePath}/Icons/pagepublisher_16.png);}

See how the name of the CSS class (PT_PagePublisher) maps to the ID in the ContextMenuItem node.

I hope this helps!

You use the theme CSS. I have the following in the CSS for an extension in my dev image:

.tridion .contextmenu #TweetThis .image
{
    background-image:url({ThemePath}/images/icons/twitter-icon16x16.png);
}

TweetThis is my context menu item id, as deifined in the extension config.

In case you want to reuse an image of the current CME (Content Manager Explorer) you can use the following:

#PT_PagePublisher.item .image
{
    background-image: url({ThemePath['CME']}/Sprites/cme_5_v6.1.0.55920.0_.png);
    background-position: 0px -480px;
    height: 16px;
    width: 16px;
}

This example shows the publish icon from a 2011 SP1 install. So you can use {ThemePath['EditorName']} to access the theme path of any editor which is configured actually.

Also in some cases I have found that my images would not load on either the ribbon toolbar or the context menu, that appeared to be an authorization issue on the editors virtual directory in IIS.

I solved it by adding a Web.config file to my Theme (root) directory which will allow access to all users for the theme files (css and images).

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <!-- allow all users access to theme files -->
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>
</configuration>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!