 | HelpersUrlContent Method |
Converts a virtual (relative) path to an application absolute path and renders the result.
Namespace: HandlebarsDotNet.MvcAssembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntaxpublic static void UrlContent(
TextWriter writer,
Object context,
params Object[] arguments
)
Public Shared Sub UrlContent (
writer As TextWriter,
context As Object,
ParamArray arguments As Object()
)
public:
static void UrlContent(
TextWriter^ writer,
Object^ context,
... array<Object^>^ arguments
)
static member UrlContent :
writer : TextWriter *
context : Object *
arguments : Object[] -> unit
Parameters
- writer
- Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet - context
- Type: SystemObject
The context (model) provided by HandlebarsDotNet - arguments
- Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if
RegisterMvcHelpers is called. If so, it is registered as
url_content but you can choose your own name for this:
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("url_content", HandlebarsDotNet.Mvc.Helpers.UrlContent);
It works like
https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.content.aspx but with special cases (see below).
Usage
{{url_content [path]}}Arguments
string [path] (required) - A virtual path
Description
This helper deviates from the one used in UrlHelper in the following ways:
If the path is exactly "~" it renders the path to the virtual directory (UrlHelper renders with an ending slash), and
if it starts with "~" but not "~/" it renders the path unchanged (UrlHelper generates an argument exception for this case).
If it does start with "~/" the path is converted to an application absolute path (just like the UrlHelper one) and rendered.
Just like the UrlHelper helper it renders the argument unchanged if it doesn't start with "~".
What this means is that if the path to this helper ends with a slash the rendered output will also do that.
If the path has the resemblance of a Linux user directory (~user) it will be unchanged, otherwise if it does start with "~" then the tilde is
converted to the virtual directory where the web application is installed (usually the root "/").
If it doesn't start with "~" it will be rendered unchanged.
Examples
This example assumes this helper has been registered as "url_content" and the application is installed in the web root.
"~" = {{url_content "~"}}
"~/" = {{url_content "~/"}}
"~/favicon.ico" = {{url_content "~/favicon.ico"}}
"~user/" = {{url_content "~user/"}}
"~" =
"~/" = /
"~/favicon.ico" = /favicon.ico
"~user/" = ~user/
See Also