CurrentToken only works if alias is set


Hello Piedone,

I found out the reson why CurrentContent token did sometimes not work for me
(regarding https://orchard.codeplex.com/workitem/19693?FocusElement=CommentTextBox):

if a page has no alias, ContentTokens.CurrentContent return a new dummy item.

I don't know why my migration Controller sometimes leaves Content items with no alias, but to handle such content items I have slightly modified your CurrentContent accessor: to handle Contents/Item/Display:

private IContent CurrentContent
            if (_currentContent == null)
                string strRequestPath = _workContextAccessor.GetContext().HttpContext.Request.AppRelativeCurrentExecutionFilePath.Substring(1).Trim('/');
                var itemRoute = _aliasService.Get(strRequestPath);
                if (itemRoute == null) {
                    if (strRequestPath.StartsWith("Contents/Item/Display/")) {
                        string strContentId = strRequestPath.Replace("Contents/Item/Display/", "");
                        _currentContent = _contentManager.Get(Convert.ToInt32(strContentId));
                    else _currentContent = _contentManager.New("Dummy"); // _currentContent isn't null so chained tokens don't throw a NE
                else _currentContent = _contentManager.Get(Convert.ToInt32(itemRoute["Id"]));

            return _currentContent;

Works perfect for me. Would be great if you could add this to your code. Thanks.
Closed May 23, 2014 at 9:27 PM by Piedone
Thanks for the suggestion. Added the implementation with some changes.


Piedone wrote May 23, 2014 at 9:27 PM

Fixed in changeset 23fc21f1fd0e

dpomt wrote May 26, 2014 at 8:29 PM


still an issue.

It is not sufficient to handle
You need also handle
Otherwise, previewing an item through dashboard will lead to same "error" as before (all items are displayed since the dummy item is created).

Piedone wrote May 27, 2014 at 10:14 AM

Fair point, added it.