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
.
[PublicApi]
public interface ILinkService : ICanDebug
- Inherited Members
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
Base()
A base url for the current page, for use in html-base tags
string Base()
Returns
Image(string, object, object, NoParamOrder, 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
string Image(string url = null, object settings = null, object factor = null, NoParamOrder noParamOrder = default, 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
url
stringThe image url. Use an empty string if you want to just get the params for re-use.
settings
object- A settings name such as "Content", "Lightbox" etc. (new 17.06)
- A standardized Image-Settings object like Settings.Images.Content - see https://go.2sxc.org/settings
- Or a dynamic object containing settings properties (this can also be a merged custom + standard settings)
- Or a specially prepared IResizeSettings object containing all settings.
If this is provided, only
factor
will still be respected, all other settings likewidth
on this command will be ignored.
factor
objectA multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
noParamOrder
NoParamOrderfield
IFieldWIP v13.04 - not final yet
width
objectOptional width parameter. Usually takes the default from the
settings
.height
objectOptional height parameter. Usually takes the default from the
settings
.quality
objectOptional quality parameter. Usually takes the default from the
settings
.resizeMode
stringOptional resize-mode, like
crop
ormax
. Usually takes the default from thesettings
.scaleMode
stringOptional scale-mode to allow up-scaling images like
up
orboth
. Usually takes the default from thesettings
.format
stringOptional file format like
jpg
orpng
aspectRatio
objectAspect Ratio width/height, only relevant if a
width
is supplied. Can't be used together with height. Usually takes default from thesettings
or is ignored.type
stringOptional type changes how the link is generated. Possible values are:
- null / not specified / empty = return link as is generated
"full"
return link with protocol and domain. If that was missing before, it will add current protocol/domain if possible, but not on relative./
or../
links"//"
return link with//domain
. If that was missing before, will add current domain if possible, but not on relative./
or../
links
parameters
object- the parameters either as
id=47&name=daniel
(Dnn also supports/id/47/name/daniel
) - in 2sxc 12.05+ it can also be an IParameters
- the parameters either as
Returns
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(NoParamOrder, int?, string, object, string, string)
returns a link to the current page with parameters resolved in a way that DNN wants it
string To(NoParamOrder noParamOrder = default, int? pageId = null, string api = null, object parameters = null, string type = null, string language = null)
Parameters
noParamOrder
NoParamOrderpageId
int?optional page ID (TabId) - if not supplied, will use current page
api
stringoptional api url "api/name/method?id=something"
parameters
object- the parameters either as
id=47&name=daniel
(Dnn also supports/id/47/name/daniel
) - in 2sxc 12.05+ it can also be an IParameters
- the parameters either as
type
stringOptional type changes how the link is generated. Possible values are:
- null / not specified / empty = return link as is generated
"full"
return link with protocol and domain. If that was missing before, it will add current protocol/domain if possible, but not on relative./
or../
links"//"
return link with//domain
. If that was missing before, will add current domain if possible, but not on relative./
or../
links
language
string- If not set,
null
or empty""
will use the specified pageId (pageIds can be language specific); api would always be the current language - If set to
"current"
will adjust pageId to use the language of the current language. API will be as before, as it was alreadycurrent
- future (not implemented yet)
"primary"
would link to primary language - future (not implemented yet)
"en"
or"en-us"
would link to that specific language (page and API)
- If not set,
Returns
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"