Image on Orchard CMS Menu items - orchardcms

How to have images to my navigation items in orchard ? In my orchard application I had added 6 navigation items. How to add images to all items there?

As a follow-up on #Xceno's answer, this is what I did when I wanted this functionality:
Add a textfield to the MenuPart in content definition, called 'Icon'
Override 'MenuItemLink.cshtml', with the following content (I used font awesome for icons, change the 'fa' stuff for whatever you use):
#{
var icon = Model.Content.ContentItem.MenuPart.Icon.Value;
}
<a href="#Model.Href">
#if (!string.IsNullOrEmpty(icon)) {
<i class="fa fa-#icon"></i>
}
<span class="nav-label">#Model.Text</span>
</a>

There was a similar question some time ago:
Orchard CMS: Modifying a menu item alternate and iterating over the items
You could for example write an alternate for the MenuItemLink and add your images there.
From the other answer:
MenuItemLink.cshtml
<a href="#Model.Href" class="my-super-cool-custom-link">
<img src="wherever/img.jpg" />#Model.Text
</a>

Related

Get title of an HTML Widget in OrchardCMS

How do I get title of a HTML widget (in this case the "default" TripelFirst) in Orchard CMS? Newbie question, but I can't figure it out.
This is the code, I just can't figure out how to get the title into the "panel-heading" div.
#if (Model.TripelFirst != null || Model.TripelSecond != null || Model.TripelThird != null) {
<div class="row">
#if (Model.TripelFirst != null) {
<div class="col-md-4 panel panel-success" runat="server" id="TripelFirst">
<div class="panel-heading">#Model.TripelFirst.Title()</div>
<div class="panel-body">#Model.TripelFirst.Body</div>
</div>
}
#if (Model.TripelSecond != null) {
<div class="col-md-4 panel panel-success" runat="server" id="TripelSecond">#Display(Model.TripelSecond)</div>
}
#if (Model.TripelThird != null) {
<div class="col-md-4 panel panel-success" runat="server" id="TripelThird">#Display(Model.TripelThird)</div>
}
</div>
}
First, it seems you are confusing zone and widget. TripelFirst is a zone, not a widget (see "So what are zones really?" for a more in-depth explanation of what a zone is). A zone should be seen as a placeholder, a container to which the widgets will be added. Orchard has a rich composition model where many decoupled services participate in the rendering of the page. The zone itself knows almost nothing about what's inside of it, it will just delegate rendering to its contents (such as widgets) when time comes. As such, the zone will not provide the easiest way to get to the title of the widgets it contains.
By far the easiest way to customize the rendering in Orchard is to do it from the right place :D Case in point, in this case, you might want to override the specific template for the widget, or a template for its wrapper (all shapes in Orchard can have wrappers which are templates that render around the shape itself).
This may look a little intimidating at first, but Orchard provides a marvelous tool out of the box that makes it easy to discover the shape structure of the page. Enable the "shape tracing" feature from the designer tools module on your dev machine (never activate this in production of course), and you'll get a nice Firebug-like debugging panel on the bottom of the page, that you can use to explore the tree of shapes/templates, the model for each of them, etc.
Another concept that is essential to understand rendering in Orchard is the placement file, which primarily describes in what order shapes representing a content item should get rendered.
In the end, to control the rendering of the title of a widget that goes into the TripelFirst zone, find the what template you need to override in your theme using shape tracing, then modify the rendering in this template to be exactly what you need.
Here's an example of code that you can put in a content part template override (such as Parts.Title.cshtml), that first finds the content item for the current part, then gets to the Title part, and displays it as a link.
#{
Orchard.ContentManagement.ContentItem contentItem =
Model.ContentPart.ContentItem;
string title = Model.Title.ToString();
}
<h2>#Html.ItemDisplayLink(title, contentItem)</h2>
Using the Shape Tracing tool, it helped me understand the model structure. Now I'm not saying this is the way the Orchard team wants this done, but this is how I ended up solving the problem.
#if (Model.SideItems != null)
{
<div class="col-md-12"> </div>
var sideWidgetItems = ((IEnumerable<dynamic>)Model.SideItems.Items).Where(x => x.ContentItem.ContentType == "HtmlWidget");
if (sideWidgetItems.Any())
{
foreach (var item in sideWidgetItems)
{
<div class="col-md-12">
<div class="panel panel-success">
<div class="panel-heading">#Html.Raw(item.ContentItem.Content.Parts[3].Title)
</div>
<div class="panel-body">#Html.Raw(item.ContentItem.Content.Parts[1].Text)
</div>
</div>
</div>
}
}
}

Set styleClass for Selected treeNodes

From time to time I stumble over the following issue, that might be easy to solve. But maybe I simply don't get it.
In a XPage treeNode, e.g. used in xe:navigator of xe:applicationLayout (pageTreeNode, placeBarActions, etc.) I wonder how to influence the styleClass property so that I can influence the "selected color".
<xe:this.titleBarTabs>
<xe:pageTreeNode label="Label Acc1"
selection="/Admin/Acc1/.*" page="/xpAdminAcc1.xsp"
styleClass="bg-info">
</xe:pageTreeNode>
<!--- ... -->
</xe:this.titleBarTabs>
In this example the styleClass 'bg-info' would be assigned always to the titleBarTab. That's the tab's background. For selected tabs the class "active" gets assigned automatically: class"bg-info active".
Is there a way to define, e.g. class bg-primary to be used for active?
I'm using the bootstrap3 theme. This is the HTML generated code. As you can see, the only difference is that the class of the activated menu item contains the class "active":
<div class="col-sm-12 col-md-12 applayout-titlebar-tabsarea" role="navigation">
<ul id="view:_id1:_id2:appLayout_tb" class="nav nav-tabs applayout-titlebar-tabs" role="tablist">
<li class="menu-item active">
<a role="tab" href="/LAP/MYDB.nsf/xpAdminAcc1.xsp" class="bg-info active">Label Acc1</a>
</li>
<li class="menu-item">
<a role="tab">Label Acc2</a>
</li>
<li class="menu-item">
<a role="tab" href="/LAP/MYDB.nsf/xpAdminAcc2.xsp" class="bg-info">Label Acc2</a>
</li>
<!-- -->
If you add a stylesheet to your application and specify the styling you want to apply for that class, then because that's at application level as opposed to server level, the standard rules for CSS (Cascading Style Sheets, so styles cascade down and get extended / overridden) will apply and the application level will take precedence. Just remember to add the application stylesheet as a resource on your Theme resource / layout Custom Control / XPage. XPage is least preferable, because it needs adding in multiple places.
The easiest method is to use Firebug or other inspection tool, select the element, find the CSS that's setting the current theme, copy and paste that into your application's stylesheet and override the settings accordingly.
Here's an example with a slightly different element:
My CSS is:
.nav-pills > li.active > a, .nav-pills > li.active > a:focus, .nav-pills > li.active > a:hover {
background-color:red;
}

Kentico - Bootstrap carousel to hide controller if there's only one item

I'm implementing a bootstrap 3 carousel on kentico 9 and need some help with automatically hiding the carousel control (including the circle indicator and the next/previous arrow) if there's only one item left, if possible.
What I've done for the carousel was setting up a new page type for this in which each banner is a page in the content tree under /hero/ folder. Then used 2 repeaters: the first one displays the circle indicator; the second one displays the banner info. All worked well.
Here's how the indicator repeater is set up:
Content before: <ol class="carousel-indicators">
Content after </ol>
Item transformation: <li data-target="#hero-banner" data-slide-to="<%# DataItemIndex%>" class="<%# (DataItemIndex == 0 ? "active" : "" ) %>"></li>
It means the first circle is always there. How to hide it and get rid of the <ol> tags in content before/after?
The next/previous arrows are again in the webpart zone content after, which has this html:
<a class="left carousel-control" href="#hero-banner" data-slide="prev"><span class="icon-prev"></span></a>
<a class="right carousel-control" href="#hero-banner" data-slide="next"><span class="icon-next"></span></a>
</div> <!--/#hero-banner-->
Using content before/after is like hard-coding it onto the page, but I don't know how to make it displayed dynamically and automatically only when we have more than one item. Could you help?
you can use <%# DataItemCount %> One of the [Transformation methods][1]
[1]: https://docs.kentico.com/display/K8/Reference+-+Transformation+methods to determine how many items there are. Then just have the html added in if there is more than one. Something like
<%# If(DataItemCount > 1,'html for more than one item','html for only one') %>
Of course, if you are using the envelope before / after to show arrows, you could also use jquery to determine how many items are there & hide the arrows based off that.
$(function(){
if($(".carousel-indicators li").length == 1){
$(".left.carousel-control").hide();
$(".right.carousel-control").hide();
}
});

Customizing the entire markup for the orchard cms navigation zone

I've been searching high and low for the past couple of days for the file(s) in Orchard where I can customize the markup used for the navigation
Traversing the tree in the Designer Tool and looking at the template and HTML views doesn't help much seeing as the MenuItemLink renders the <li> in the HTML view but nothing renders it in the template view. So I am quite stumped.
The original markup is like so (Taken from the Designer Tools Zone [Navigation]):
<div class="zone zone-navigation">
<article class="widget-navigation widget-menu-widget widget">
<nav>
<ul class="menu menu-main-menu">
<li class="first">
Work
</li>
</ul>
</nav>
</article>
</div>
What I need is to customize the classes on the <ul> and <li> elements, really.
If possible I'd love to be able to customize it all so I didn't need the <div class="zone zone-navigation"> for example.
But is this even possible?
<li> element is rendered by MenuItem shape (Core\Shapes\MenuItem.cshtml)
<nav> and top <ul> elements are rendered by Menu shape
(Core\Shapes\Menu.cshtml)
<a> element is rendered by MenuItemLink shape (Core\Shapes\MenuItemLink.cshtml)
If you want to override the defaults, simply put appropriate Menu.cshtml, MenuItem.cshtml or MenuItemLink.cshtml files in your theme (or better - copy the default one(s) and alter). Those will be used then instead of the default ones I wrote about above.

What is a WAI-ARIA compliant implementation for navigation bar/menu

We are in the process of implementing (i.e. adding) WAI-ARIA support to the main navigation menu of a web portal. Menu is the one shown here:
Menu is implemented by means of classic <ul> / <li> / <a> DOM tree, styled with CSS to look like horizontal tabs.
What is a WAI-ARIA compliant implementation for such a widget?
I've read many parts of most recent WAI-ARIA specs from w3org for a general understanding, taxonomy, and so on.
Then I've read about several examples of UI widget implementations. I could not find any example specifically targetd at such a CSS navigation menu. The closest widgets I've always found around are the Menu, the MenuBar, and the TabPanel. Of course I also looked in Free ARIA Community group (where this question was originally posted).
I'd say that none of those widgets exactly match a (CSS) navigation menu. As an example, TabPanel may control some content in the page (--> aria-controls), maybe MenuBar too; but I'm not at all sure that a navigation menu controls content in the page (it controls the next page to show). Without going further, there are some other differences as well.
References are at the end of the post. If anyone as better (or more fit) examples of navigation menu, we'd be glad to know about them.
References
https://developer.mozilla.org/en-US/docs/Accessibility/ARIA/ARIA_Test_Cases#Menubar_and_Menu
http://wiki.jqueryui.com/w/page/38666403/Menubar
http://www.oaa-accessibility.org/examplep/menubar2/
http://test.cita.illinois.edu/aria/menubar/
http://dev.aol.com/dhtml_style_guide#menu
http://whatsock.com/modules/aria_tabs_menu_modules/demo.htm
http://www.w3.org/TR/wai-aria-practices/#menu
http://www.w3.org/TR/wai-aria/roles
http://www-03.ibm.com/able/resources/wai_aria_intro.html
A possible implementation would be:
HTML structure:
<div> <!-- Outer wrapper -->
<ul> <!-- Main navigation bar container -->
<li> <!-- First-level item without submenu -->
<a> <!-- Destination URL -->
</a>
</li>
<li> <!-- First-level item with submenu -->
<a> <!-- Destination URL -->
</a>
<ul> <!-- Second-level menu container -->
<li> <!-- Second-level item -->
<a>
</a> <!-- Destination URL -->
</li>
</ul>
</li>
</ul>
</div>
Roles:
role=”navigation” for outer wrapper <div>
role="menubar" for <ul> navigation bar container
role="menu" for second-level <ul> containers
role="presentation" for first- and second-level <li> menu items (they are not needed in the exposed accessible menubar structure)
role="menuitem" for first- and second-level <a> menu items
Properties:
aria-haspopup="true" for first-level <a> menu items having a submenu
aria-labelledby="ID of previous <a> menu item" for second-level <ul> containers
States:
aria-selected="true" on currently visited first- or second-level <a> item; aria-selected="false" on the other <a> items. That is to enforce the concept “selected <==> current page”
aria-expanded="true/false" for second-level <ul> containers
aria-hidden="true/false" for second-level <ul> containers
aria-activedescendant="" for main <ul> navigation bar container. This is an alternative to working with tabindex
tabindex=0 on currently visited <a> item; tabindex=-1 on the other <a> items. That is in order to first focus on the current page when tabbing to the navigation bar. It is an alternative to working with aria-activedescendant
Keyboard:
Tab: Move focus in/out of the menu from other points in the web application.
Shift+Tab: Move focus in/out of the menu from other points in the web application, in the reversed order.
Right arrow: Next navigation bar item
Left arrow: Previous navigation bar item
Enter: Activate currently focused item (i.e. navigate to corresponding URL)
Space: Activate currently focused item (i.e. navigate to corresponding URL)
Aug/2014: aria-selected Vs menuitem
In reply to #Joshua Muheim comment: now I can see from here, as well as from his reference, that aria-selected attribute is not allowed for menuitem role.
As I read from this recent SO answer there are some solutions given the current state of things, and there is a new proposed attribute too.
The ARIA design patterns provide expected UI behaviour for a range of custom controls http://www.w3.org/TR/wai-aria-practices/#aria_ex use of esc key to close and return to triggering element upon close is standard UI across desktop and web. Try it on any Google docs app (for example).
You can get a menu to announce 'X of Y' information by adding the aria-posinset and aria-setsize attributes to the elements with role=menuitem.
+Escape key should close an open menu and return focus to the element that opens it.
Escape to close is a standard going way back, it is expected behavior by many users.

Resources