Rendering URLs
Render Page URLs and Media URLs in Razor functions
To render a page URL or a media URL in a C1 CMS compliant way, use ~/page(...) and ~/media(...)
:
@inherits CompositeC1Contrib.RazorFunctions.CompositeC1WebPage @using Composite.Data @using Composite.Data.Types @using CompositeC1Contrib.RazorFunctions @functions { [FunctionParameter("Page" , "...")] public DataReference<IPage> aPage { get; set; } [FunctionParameter("Image" , "...")] public DataReference<IMediaFile> anImage { get; set; } } <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> NEW! <a href="/page(@aPage.Data.Id)">@aPage.Data.Title</a> <br /> <img src="/media({@anImage.Data.Id})" alt="..."/> </body> </html>
Alternatively, you can use the ad-hoc helper methods from the Html
helper: PageUrl
and MediaUrl
:
@inherits CompositeC1Contrib.RazorFunctions.CompositeC1WebPage @using Composite.Data @using Composite.Data.Types @using CompositeC1Contrib.RazorFunctions @functions { [FunctionParameter("Page" , "...")] public DataReference<IPage> aPage { get; set; } [FunctionParameter("Image" , "...")] public DataReference<IMediaFile> anImage { get; set; } } <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <a href="@Html.C1().PageUrl(@aPage.Data)">@aPage.Data.Title</a> <br /> <img src="@Html.C1().MediaUrl(@anImage.Data)" alt="..."/> </body> </html>
PageUrl
's input parameter can be one of these types:IPage
,GUID
orstring
(with the Page ID)MediaUrl
's input parameter can be of these types:IMediaFile
,GUID
orstring
(with the media's key path)