Interface ILinkService
Helpers to create links to
- Pages
- APIs
- Images
As well as create base-tag links (important for SPAs)
You will never create this yourself, as get this automatically in Razor or WebAPIs on an object called Link
.
Inherited Members
Namespace: ToSic.Sxc.Services
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi_Stable_ForUseInYourCode]
public interface ILinkService : ICanDebug
Remarks
History
- Created ca. v2 as
ToSic.Sxc.Web.ILinkHelper
- Moved to this new
Services.ILinkService
in v13.05. The previous name will continue to work, but newer features will be missing on that interface.
Methods
| Improve this Doc View SourceBase()
A base url for the current page, for use in html-base tags
Declaration
string Base()
Returns
Type | Description |
---|---|
string |
Image(string, object, object, string, IField, object, object, object, string, string, string, object, string, object)
Generate an Image-Resizing link base on presets or custom parameters.
It will also ensure that the final url is safe, so it will encode umlauts, spaces etc.
Note that you can basically just use presets, or set every parameter manually.
- All params are optional.
- Some combinations are not valid - like setting a factor and a width doesn't make sense and will throw an error
- Most parameters if set to 0 will cause a reset so that this aspect is not in the URL
Declaration
string Image(string url = null, object settings = null, object factor = null, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", IField field = null, object width = null, object height = null, object quality = null, string resizeMode = null, string scaleMode = null, string format = null, object aspectRatio = null, string type = null, object parameters = null)
Parameters
Type | Name | Description |
---|---|---|
string | url | The image url. Use an empty string if you want to just get the params for re-use. |
object | settings |
|
object | factor | A multiplier, usually used to create urls which resize to a part of the default content-size. Eg. 0.5. |
string | noParamOrder | |
IField | field | WIP v13.04 - not final yet |
object | width | Optional width parameter. Usually takes the default from the |
object | height | Optional height parameter. Usually takes the default from the |
object | quality | Optional quality parameter. Usually takes the default from the |
string | resizeMode | Optional resize-mode, like |
string | scaleMode | Optional scale-mode to allow up-scaling images like |
string | format | Optional file format like |
object | aspectRatio | Aspect Ratio width/height, only relevant if a |
string | type | Optional type changes how the link is generated. Possible values are:
|
object | parameters |
|
Returns
Type | Description |
---|---|
string |
Remarks
Usually a factor is applied to create a link which is possibly 50% of the content-width or similar.
In these cases the height is not applied but the aspectRatio is used, which usually comes from settings
if any were provided.
History
- New in 2sxc 12.03
- type added ca. v12.08
- Option to use IResizeSettings added in v13.03
factor
originally didn't influence width/height if provided here, updated it v13.03 to influence that as wellfield
being added in 13.04, not ready yet
To(string, int?, string, object, string, string)
returns a link to the current page with parameters resolved in a way that DNN wants it
Declaration
string To(string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", int? pageId = null, string api = null, object parameters = null, string type = null, string language = null)
Parameters
Type | Name | Description |
---|---|---|
string | noParamOrder | |
int? | pageId | optional page ID (TabId) - if not supplied, will use current page |
string | api | optional api url "api/name/method?id=something" |
object | parameters |
|
string | type | Optional type changes how the link is generated. Possible values are:
|
string | language |
|
Returns
Type | Description |
---|---|
string |
Remarks
History
- v12 added the api parameter for liking APIs of the current app
- In v12.05 the type of parameters was changed from string to object, to allow IParameters as well
- In v13.02 introduced language with "current"