Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
This seems like it should be a pretty obvious question, and others have asked this, but their solution doesn't seem to work for me.
On a given page, I want to change a style in the template based on which page is currently active.
In Umbraco 8, I used the following code, which worked brilliantly:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var currentPageURL = Url.Action()+"/"; }
In Umbraco 11, the same code gives me an empty string.
The following code seems to be recommended:
@inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage @{ var currentPageURL = Umbraco.AssignedContentItem; }
However, the result is "UMBRACO.CMS.WEB.COMMON.PUBLISHEDMODELS.SITECONTENT" whereas I want to know the actual value.
Are there any suggestions on what I need to do to correct this? Thanks! Luke
Hi,
var currentPageURL = Umbraco.AssignedContentItem;
Gives you the object not url of the page.
You will need to ask for the url like this:
var currentPageURL = Umbraco.AssignedContentItem.Url();
You should also be able to do
var currentPageURL = Model.Url();
Brilliant. Thank-you!!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Retrieve Current Page
This seems like it should be a pretty obvious question, and others have asked this, but their solution doesn't seem to work for me.
On a given page, I want to change a style in the template based on which page is currently active.
In Umbraco 8, I used the following code, which worked brilliantly:
In Umbraco 11, the same code gives me an empty string.
The following code seems to be recommended:
However, the result is "UMBRACO.CMS.WEB.COMMON.PUBLISHEDMODELS.SITECONTENT" whereas I want to know the actual value.
Are there any suggestions on what I need to do to correct this? Thanks! Luke
Hi,
var currentPageURL = Umbraco.AssignedContentItem;
Gives you the object not url of the page.
You will need to ask for the url like this:
var currentPageURL = Umbraco.AssignedContentItem.Url();
You should also be able to do
var currentPageURL = Model.Url();
Brilliant. Thank-you!!
is working on a reply...