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

How do I add an icon to my Tridion 2011 GUI Extension context-menu item?
Is it in the theme or GUI Extension config?
Is the size 16px?

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>

Related

Css in different folder

I am trying to make something like "templates system" it might allow user to change site template. In admin panel for example.
My current files structure
-Controllers
-Models
-Views
--Templates
---DefaultTemplate
----css
-----style.css
----Index.cshtml
In default controller (home) i check current template name and show right view
private ViewResult TemplateView(string viewName)
{
return View($"~/Views/Templates/{GlobalSettings.CurrentTemplate}/{viewName}.cshtml");
}
And some template View (Index.cshtml)
.....
<link rel="stylesheet" href="~/Views/Templates/DefaultTemplate/css/style.css" type="text/css" />
.....
But I dont know how write correct path to my css\js\ images in right template forder.
I have tried
./css/style.css
#Url.Content("/css/style.css")
But in result HTML it is like mysite.com/css/style.css so i got 404 (not found)
I have also tried this
~/Views/Templates/DefaultTemplate/css/style.css
In this case i got 404 too.
So, can anybody help me? How to write correct URL to CSS, images, hs etc ?
The web.config file in the /Views folder restricts all access to files in the folder by default:
Add code to your web.config file:
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
Note: It's not good practice to store css files inside view folder.

replace alfresco share 4.2 login screen logo

In Alfresco share 4.2 enterprise, I want to just replace the default logo from alfresco share login page. Below blog shows how to create a custom login screen.
http://blogs.alfresco.com/wp/developer/2011/11/03/advanced-share-customization-part-2/
However I do not want to create a complete new login page, just want to replace the logo with the same default theme. Could some one suggest how to replace the logo using extensions option.
There are a few methods in which you may replace the default logo, but since you've asked about the extensions option, here's how you would do this...
0) Assume we are creating an AMP, but you can also do steps 1 & 2 in the extensionRoot directory (/tomcat/shared/ - assuming you are using Tomcat)
1) Create a new module extension XML login-extensions.xml under /alfresco/web-extension/site-data/extensions and add the following XML
<extension>
<modules>
<module>
<id>Login Customization Extension Example</id>
<auto-deploy>true</auto-deploy>
<customizations>
<customization>
<targetPackageRoot>org.alfresco</targetPackageRoot>
<sourcePackageRoot>example.login.customizations</sourcePackageRoot>
</customization>
</customizations>
</module>
</modules>
</extension>
2) Next create a response template resources.get.html.ftl at
/alfresco/web-extension/site-webscripts/example/login/customizations/components/head and add the following Freemarker
<#markup id="example-login-resources" action="after" target="resources">
<link rel="stylesheet" type="text/css" href="${url.context}/res/example/login/customizations/components/head/resources.css" ></link>
</#markup>
In the FTL above, I'm linking to a CSS resource file, you could alternatively just add inline-style css between the #markup tags, but for best practices, assume the CSS is a just a resource file and so...
3) Create a resources.css file located at /META-INF/example/login/customizations/components/head (or alternatively, this is not recommended, but in the exploded Share.war directory, create the file at path /example/login/customizations/components/head) and apply the proper css to change the logo...
The CSS that you want to override:
.theme-company-logo {
background: url("images/logo.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
height: 48px;
width: 428px;
}
Make sure you set the height to match the height of your custom logo.

Images not displaying from theme layout (Orchard CMS)

I'm trying to create theme for Orchard CMS. The template I have wasn't made for it so I have some troubles displaying images from Layout.cshtml.
This is the current folder structure on my web server (theme folder structure only):
Theme/Content/Images/Image.jpg
Theme/Views/Layout.cshtml
Theme/Styles/Site.css
The following line doesn't display image (located in Layout.cshtml):
<img src="../Content/Images/bgBig.jpg" alt="Big background image" />
However, this line does display the image (located in Site.css):
background-image:url('../Content/Images/bgLines.png');
I believe the problem is that Layout.cshtml doesn't display the image from Theme/Views/Layout.cshtml, but from the other location. If someone knows what would be that location or how to override it I would be thankful.
I might be a little late, but this may be of help to others.
To get the current theme and then build an dynamic path (as opposed to an absolute path) use this:
WorkContext.CurrentTheme: Gets the current working theme ExtensionDescriptor.
Then give it to the Html.ThemePath URL builder:
Ex.
Html.ThemePath(WorkContext.CurrentTheme, "/Content/Images/SomeImage.png")
Have fun!
Best regards,
Tiago.
When adding images in Layout.cshtml you should use the full path to your theme (eg. /Themes/My.Theme/Content/Images/MyImage.jpg). Remember that the paths you provide in [img] tag are relative to the URL in browser, not the path on the server. In MVC those are almost never equal.
Layout.cshtml view file gets loaded as a part of every single request, so relative paths placed inside will almost always break.
Imagine you have two Orchard pages: site.com/mypage and site.com/something/mypage. Layout.cshtml gets rendered in both of them. Relative URLs working for the first will surely break when you access second one.
CSS stylesheets are loaded directly by specifying absolute path to the physical files in /Themes/YourTheme/Styles folder (default), so in this case relative URLs will work.
HTH
Thx Tiago for your solution. I think this is in fact the correct solution, as opposed to linking the full path which I think would require the Orchard site to be on the root of the domain.
The full image reference of the original question would look like this:
<img src="#Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Content/Images/bgBig.jpg"))" alt="Big background image" />
I'm surprised that nobody's mentioned that you need the following web.config in the folder in which your images/scripts/styles reside (see the orchard docs)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<httpHandlers>
<!-- iis6 - for any request in this location,
return via managed static file handler -->
<add path="*" verb="*" type="System.Web.StaticFileHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers accessPolicy="Script,Read">
<!-- iis7 - for any request to a file exists on disk,
return it via native http module.
accessPolicy 'Script' is to allow for a managed 404 page. -->
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule"
preCondition="integratedMode" resourceType="File"
requireAccess="Read" />
</handlers>
</system.webServer>
</configuration>
Additionally, as others have pointed out, this is the most reliable way of locating an image:
<img src="#Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Content/Header.png"))" />
if you examine the source, it should show you where it's trying to find that image and failing. It's most likely the relative path it's having issue with, try an absolute path in the css to see if that's the issue. without the actual site, I can't know for sure.

problem with css file

I'm having problem with themems.
I have app_themes folder in my application that have a mytheme folder.In that folder
I hvae placed a css file.
I have used this theme thruoghout the application.
using the web config file....follwing is the code.
<System.web>
<pages theme="mytheme"></pages>
</System.web>
it's worikng fine..but problem is tht i dont want htis theme on a particular page.
for this i have used
Enablingtheme ="false" in pagedirective.but it is still appliying to the page.
Please suggest something to me...
thanx in advance..
...
Well EnablingTheme is not the correct property name. it's
EnableTheming="false"
I'd check that you haven't a typo in there first.

Reference app relative virtual paths in .css file

Assume I have an "images" folder directory under the root of my application. How can I, from within a .css file, reference an image in this directory using an ASP.NET app relative path.
Example:
When in development, the path of ~/Images/Test.gif might resolve to /MyApp/Images/Test.gif while, in production, it might resolve to /Images/Test.gif (depending on the virtual directory for the application). I, obviously, want to avoid having to modify the .css file between environments.
I know you can use Page.ResolveClientUrl to inject a url into a control's Style collection dynamically at render time. I would like to avoid doing this.
Unfortunately Firefox has a stupid bug here... the paths are relative to the path of the page, instead of being relative to the position of the CSS file. Which means if you have pages in different positions in the tree (like having Default.aspx in the root and Information.aspx in the View folder) there's no way to have working relative paths. (IE will correctly solve the paths relative to the location of the CSS file.)
The only thing I could find is this comment on http://www.west-wind.com/weblog/posts/269.aspx but, to be honest, I haven't managed to make it work yet. If I do I'll edit this comment:
re: Making sense of ASP.Net Paths by
Russ Brooks February 25, 2006 # 8:43
am
No one fully answered Brant's question
about the image paths inside the CSS
file itself. I've got the answer. The
question was, "How do we use
application-relative image paths
INSIDE the CSS file?" I have long been
frustrated by this very problem too,
so I just spent the last 3 hours
working out a solution.
The solution is to run your CSS files
through the ASPX page handler, then
use a small bit of server-side code in
each of the paths to output the root
application path. Ready?
Add to web.config:
<compilation debug="true">
<!-- Run CSS files through the ASPX handler so we can write code in them. -->
<buildProviders>
<add extension=".css" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
<httpHandlers>
<add path="*.css" verb="GET" type="System.Web.UI.PageHandlerFactory" validate="true" />
</httpHandlers>
Inside your CSS, use the Request.ApplicationPath property
wherever a path exists, like this:
#content {
background: url(<%= Request.ApplicationPath
%>/images/bg_content.gif) repeat-y;
}
.NET serves up ASPX pages with a MIME type of "text/html" by default,
consequently, your new server-side CSS
pages are served up with this MIME
type which causes non-IE browsers to
not read the CSS file correctly. We
need to override this to be
"text/css". Simply add this line as
the first line of your CSS file:
<%# ContentType="text/css" %>
In case you didn't know you could do this...
If you give a relative path to a resource in a CSS it's relative to the CSS file, not file including the CSS.
background-image: url(../images/test.gif);
So this might work for you.
Make you life easy, just put images used in your CSS in the /css/ folder alongside /css/style.css. Then when you reference your images, use relative paths (e.g. url(images/image.jpg)).
I still keep images that are displayed with a <img> in an /images/ folder. Photos for example are content, they are not part of the website's skin/theme. Thus, they do not belong in the /css/ folder.
Marcel Popescu's solution is using Request.ApplicationPath in the css file.
Never use Request.ApplicationPath - it is evil! Returns different results depending on the path!
Use the following instead.
background-image: url(<%= Page.ResolveUrl("~/images/bg_content.gif") %>);
Put your dynamic CSS in a user control in an .ascx file and then you do not need to run all your css files through the asp.net page processer.
<%# Control %>
<style type="text/css>
div.content
{
background-image:(url(<%= Page.ResolveUrl("~/images/image.png") %>);
}
</style>
But the easiest way to solve the ~ problem is to not use a ~ at all. In Visual Studio, in Solution Explorer, right click your application, select Properties Window and change the Virtual Path to /.
On Windows 7, IIS 7.5:
Not only do you have to do the steps mentionned by Marcel Popescu.
You also need to add a handler mapping in IIS 7.5 handler mappings. So that IIS knows that *.css must be used with the System.Web.UI.PageHandlerFactory
It's not enough to just set the stuff in the web.config file.
Inside of the .css file you can use relative paths; so in your example, say you put your css file in ~/Styles/mystyles.css. You can use url(../Images/Test.gif) as an example.
I was having difficulty in getting background images to display for content containers and have tried many solutions similar to other posted here. I had set the relative path in the CSS file, set it as a style on the aspx page I wanted the background to display - nothing worked. I tried Marcel Popescu's solution and it still didn't work.
I did end up getting it to work following a combination of Marcel's solution and trial and error. I inserted the code into the web.config, inserted the text/css line into my CSS file but I removed the background property in the CSS file altogether and set it as a style on the content container in the aspx page I wanted the background to display.
It does mean that for each or any other pages that I want to display the background I will need to set the style background property but it works beautifully.

Resources