Current Page Properties

Joshua Adams asked on March 9, 2016 15:57

Hypothetically if you want to get some properties out of the current page, without using a repeater, whats the easiest and best way to do that? I know the simple macros(DocumentName, etc) can retrieve some of those, but what about odd fields like the DocumentTeaserImage and other things of that nature and also being outside of a webpart where a macro would be resolved. The only way that I am aware of right now is to us the <%= CMS.DocumentEngine.CurrentDocument.DocumentName blah blah %> syntax. Is there another way or is this the approach that everyone uses? Just curious if I am making things harder than they need to be or if it actually is more difficult than you would think.

Hypothetical situation: You are tasked with taking the teaser image from the page(menu item doc type) and using that in the template as a background image.

Correct Answer

Jan Hermann answered on March 9, 2016 21:52

Hello Joshua,

calling ResolveMacros in ASCX layouts is not a good idea. Well, you get the result you want but why would you resolve macros when you can use API directly as in your initial post.

What I would recommend is switching your layout type from ASCX to HTML where macros are resolved automatically and then you can set the background image url like this:

~/getattachment/{%CurrentDocument.MenuItemTeaserImage%}/background.aspx

Best regards,
Jan Hermann

0 votesVote for this answer Unmark Correct answer

Recent Answers


Zachary Perry answered on March 9, 2016 16:08

I believe you can do {%CurrentDocument.GetValue("Column")%}

1 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on March 9, 2016 16:16

If you use that inside of the template, then you would need to wrap it in the resolve macros syntax using the ascx brackets. Is that the best way to do it? Should a webpart be placed on the page in whatever spot is needed and then macros entered? That way they are resolved by the webpart.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on March 10, 2016 22:48

Thanks everyone, Jan, that would be ideal, if you can still use the webparts and placeholders as well. Are there any limitations by using the HTML layout in a template vs ascx? I'm assuming the limitations are similar to those when using an html transformation as apposed to ascx, as far as server side controls and registering controls.

0 votesVote for this answer Mark as a Correct answer

Tom F answered on December 2, 2016 05:26

What kind of control do you use in your aspx markup if you just want to deal with the current page object and not deal with querying for child pages and other collections and databind etc.

I'm coming from umbraco razor land where you can just write @Model.Current.GetPropertyValue("blah") anywhere to deal with the current page.. is there something as simple for the aspx pages/templates?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.