Get title of an HTML Widget in OrchardCMS - 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>
}
}
}

Related

VoiceOver: How to prevent users from accessing objects outside the menu?

If you visit www.arbetsformedlingen.se from a mobile, you will find a menu.
If you open that menu, you can only access items within that menu since tapping outside of the menu will close the menu.
If you for some reason are using a keyboard, you cannot tab out of
that menu.
However, visitors who uses the screen reader VoiceOver in IOS can simply move out of that menu by using the swipe left/right gestures to access the previous/next object in the DOM.
Question: Is there some way to prevent those users to access objects outside of the menu when the menu is visible?
An unsuitable solution due to the CMS would be to place the main content and the menu on the same node level, like in the simplified code below:
<body>
<div class=”maincontent” aria-hidden=”false”>
// Main content.
</div>
<div class=”mobilemenu” aria-hidden=”true” style="display:none">
// Menu.
</div>
</body>
When the menu is opened, the aria-hidden and display:none are toggled in order to just show the page contents or the menu.
Another unsuitable solution would be to toggle aria-hidden to every other object when the menu is opened, but that is impossible due to performance issues.
So, any piece of advice, thoughts etc are very welcome!!!
Using HTML5, you can set the "tab-index" to positive numbers on the elements within the menu. This will set focus to those elements. `
<div class="menu-container">
<div class="menu">
<div tabindex="1">Menu Item 1</div>
<div tabindex="2">Menu Item 2</div>
<div tabindex="2">Menu Item 3</div>
</div>
</div>
This may not be the best solution depending on what your trying to accomplish and what your code structure looks like.
You'll want to be sure to use the "tab-index" attribute correctly as to not break accessibility.
Good description and example
WebAIM-tabindex-accessibility

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();
}
});

Image on Orchard CMS Menu items

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>

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.

Why isn't my list displaying in Orchard?

In Orchard 1.3.10 when I create a list it gets assigned a permalink such as /people. When I add a person to the list and go to /people the person does not display. I see
When I add a widget to display people the person displays.
Am I doing something wrong, or is this Orchard working as designed?
Using the shape tracing module I see this In my content zone:
<div class="zone zone-content"> <div class="content-control">
<div class="manage-actions">Edit</div>
<article class="content-item list">
<header>
</header>
</article>
</div>
</div>
Creating a new site fixed my issue.
On my debug site I'm able to work around the issue by changing my list sort order, but not on my real site.
I filed a bug here: http://orchard.codeplex.com/workitem/18421

Resources