Umbraco: querying latest items - umbraco

I'm a newbie in using Umbraco. The current version I'm using is v7++.
I have changed the rendering engine from MVC to webform as I'm not really good with MVC.
Current Item
item A
item B
item C
item D
The current problem I'm facing is to query the latest item under "Current item".
And here is the code I have:
annRoot.GetDescendantNodes().OrderByDescending(x => x.CreateDate);
But this line of code will definitely cause some performance issue if there is a huge amount of descendants under the "current item".
Is there a way for me to query directly for the latest item without having to retrieve the whole list of descendant.

If this line of code is used in a Razor macro then you should be able to access the last item directly by using .Last()
...OrderByDescending(x => x.CreateDate).Last();
Checkout the 'Traversing' section in this Dynamic Node Cheat Sheet ....
this is from v4.7 when razor support was initially introduced, but it should all still be relevant.

Related

Umbraco Same Url Render Page Sequence

I'm new to umbraco and using umbraco 6 latest version... Actually this is a silly mistake but makes me curious..
I've two content, let's say item a and item b.. This two item will be published alternately. so it can be access via "mysite/item_active"..
Today -> item a -> change name to item_active -> save publish -> change yesterday item active to item_b..
But somehow I forgot to use save publish yesterday.. And only click save that make the url of the content is not being updated..
Then how umbraco will choose with item to render (both item now have "mysite/item_active" url)?
The day I asked you is holiday until monday.. And I don't have access this site (because this internal company site) from home..
Are based on node? the smaller node is the one being render or the latest publish item will be rendered?
Umbraco won't allow you to save and publish two items with the same URL / node name (on the same tree level). It will automatically add version number e.g. (1) for the next node with the same name and then, friendly URL will become /mysite/item-active-1 in your case.
I tested this scenario, and Umbraco returns this information when you're trying to publish item with the same name as existing one:
So, in theory - we have two items published, but only one is still in the XML (IPublishedContent) cache, from which Umbraco is taking content first. Second item won't be visible until we will change the URLs / names to be different or perform publish on first item and then scenario described at the beggining will be applied.
Maybe it's worth to consider having it as a same page and just swaping the templates on which you can render particular properties values? Or having a content picker or something else to determine which version of the site should be marked as active and used?

Grid sorting with Telerik.Web.Mvc.UI Grid

I am using the Telerik.Web.Mvc.UI Grid to show a grid on an Asp.Net MVC website.
All of the columns are supposed to be sortable / filterable, but as you will see from the image below, the only who that actually do have a Sort / Filter in the right place are the File Name column and the Project Requested By column.
These columns are bound by the following code...
c.Bound(o => o.FileName);
c.Bound(o => o.Dto.ProjectDetailsDto.ProjectRequiredBy)
.Template(o => o.Dto.ProjectDetailsDto.ProjectRequiredBy.HasValue ? o.Dto.ProjectDetailsDto.ProjectRequiredBy.Value.ToString(Model.DateTimePattern) : "")
.HeaderHtmlAttributes(Resources.EditorLocalization.ProjectDeadline);
Let's limit the problem, and ask ourselves why the Project Name is not sortable (it isn't). The project name is bound like so :
c.Bound(o => o.Dto.ProjectName)
.Template(o => Html.ActionLink(o.Dto.ProjectName, "Details", "Project", new { projectId = o.Dto.AssetTask.ProjectId }, null))
.HeaderTemplate(Resources.EditorLocalization.ProjectName)
.Sortable(true)
.Filterable(true);
First of all, I considered that it might be that columns that use a template cannot be sorted - only they can, because we have the working case of the Project Required By Column.
Perhaps, I thought, it is the presence of the HeaderTemplate() that is causing us problems, but then why would it? Still, I can't deny, everything I believe should work, but doesn't, has a HeaderTemplate.
So - let's blame that and see what we can do... The reason I am using a HeaderTemplate is because we want to be able to be able to localise the strings used to label the columns (ie the headers). Is there any other approach we might take which would allow us to do that, but also mean we could have sorting on the grid as well?
Thanks in anticpation...
Ok - the problem was indeed down to my use of HeaderTemplate(). If I use the Title() method instead, all is well...

Where should I put data like testimonials and addresses in Umbraco?

I am fairly new to Umbraco and I am wondering where I should put pieces of random data.
I have a lot of experience with Sitecore, used it for several years, I am certified etc etc. But now I have to build something with Umbraco. At a first glance Umbraco looks inferior to Sitecore in every way, but I might be wrong about that.
So what I am wondering is, where should I put non-browsable pieces of data that are visible on several places throughout the website? I'd like to create data items in Umbraco for things like Testimonials, Offices? I'd like to have a centralized place in Umbraco where they can be maintained and reference them from a page node. But the way it looks now is that everything has to be on the page node. Which is sort ok, for your average family webpage.
Could someone please shed some light on this?
You could create another node under the man content and call it site settings and store them there that way all pages under the home page are just visible pages on the front end and all data nodes are in a separate area.
There is one property in umbraco that you can add to document types and name it "umbracoNaviHide" (for alias, the name can be anything). This allows wires in automatically to the .IsVisible() method.
var children = Model.Content.Children.Where(x => x.IsVisible());
I find this situation to be very frequent, think of slideshows. When I make an Umbraco website, under my root node I normalle havea Slideshow document type (that contains slides) and I programmatically traverse those to build the slideshow on the home page for example. This Slideshow document has that "umbracoNaviHide" property and I skip it from my menus either using the .IsVisible() method or by manually skipping specific document types.
var menuItems = Model.Content.Children.Where(x => x.DocumentTypeAlias != "Slideshow" && x.DocumentTypeAlias != "Search");
On the other hand, if you are looking for "labels", you can look at "Dictionnary" items under the "Settings" tab.
To directly answer your questions, I reccomend putting non-browsable pieces of data as children of the relevant browsable content node. (But there are other valid ways to do this, it really is up to you and what's best for your content editors.)
Hope this helps.

Umbraco drop down list with content entered by admin - xpath dropdown?

In Umbraco 6.1, I need to add a field to a Document Type that gets it's possible values from a list that an admin user can add to via the back end.
I figured I'd do this by creating a Developer/Data Type of type XPath DropDownList and have that point to a folder in my Umbraco content through the XPath Expression //Configuration/lookup-lists/course-availability. I've set the Type of Document and Value to Node Id/
This drop down list isn't displaying the SimpleTextItems that are within this folder (its empty).
Any ideas?
I believe you're looking to select content from a specific folder in your content-tree, is this correct? Look into the Multi-Node Tree Picker in this case as you can configure this pick 1-n nodes in any specific folder or type..
If the above is not what you're looking for, you might also check the uComponents dropdown that an admin with access to the Developer section can edit the 'pre-values'.
Whatever you're looking for exactly - some data type in the uComponents package is most likely the answer. If not (u'd be surprised!), you may have to code your own .
Your XPath is incorrect.
your Xpath should be something like (loads all existing documents with doctype:SimpleText and in first level of Umbraco tree)
$ancestorOrSelf/ancestor-or-self::*[#level=1]/SimpleText
Please take a look at here to see correct Xpath samples for your dropdownlist

Composite C1 console edit button available for non translated data

We are using Composite C1 version 2.1.1 with static C# data. This data is localizable (ILocalizedControlled) and is shown on top of the data tree (TreeDefinitions\GlobalData.xml). Users are able to translate the data to their selected language, but somehow it is possible to "Edit" the data before translating it. This means that when they do it wrong (i.e. in stead of first choosing "Translate Data" and then "Edit", choose "Edit" directly) translated data will appear on the source language site. Which is very annoying because the source data is lost as well.
Seems that when choosing a data item only "Translate Data" should be possible, but now four buttons are shown (Translate Data, Edit, Add and Delete). So I would like to be able to change this behavior, but can't seem to find where or how to influence this.
Hope anyone can help.
somehow it is possible to "Edit" the data before translating it.
This is because in your tree definition (TreeDefinitions\GlobalData.xml), you explicitly use EditDataAction, which does what it is supposed to do: allow editing an item using the standard edit workflow.
I suggest that instead, you create and use a custom workflow for editing items, which might have a logic to allow editing only if the data item is translated in the current language.
I don't have a ready-to-use code for that but you can check samples for custom workflows here.
Also, in the upcoming version 4.1 of Composite C1 (currently beta), you don't need to create tree definitions for static data types. They are available in the C1 Console out of the box. And you can add, edit and delete items of these types there, and the Translation feature on localized types works as expected.
Compare:
The item exposed via a Tree Definition (the issue you mentioned)
And the same item available under "Static Datatypes" (a new feature in 4.1)

Resources