Interface IPageService
Service on Kit.Page to make changes to the page - usually from Razor.
[PublicApi]
public interface IPageService
Remarks
History
- Introduced in v12.02 but on another namespace which still works for compatibility
- Moved to ToSic.Sxc.Services in v13
- Added ability to use placeholder
[original]in v13.11 - Most commands were updated to return an empty string in v14.02 so that they could be used as inline razor (previously
void)
Methods
Activate(params string[])
Activate a feature on this page, such as turnOn, 2sxc.JsCore etc.
For list of features, see Page Service to Activate Features & WebResources (JS, CSS, etc.).
string Activate(params string[] keys)
Parameters
keysstring[]One or more strings containing Page-Feature keys
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.Activate(...)
Activate(NoParamOrder, bool, params string[])
Activate a feature on this page, such as turnOn, 2sxc.JsCore etc.
For list of features, see Page Service to Activate Features & WebResources (JS, CSS, etc.).
string Activate(NoParamOrder noParamOrder = default, bool condition = true, params string[] features)
Parameters
noParamOrderNoParamOrderconditionboolCondition to determine if activation should happen
featuresstring[]One or more strings containing Page-Feature keys
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.Activate(...)
Remarks
- This overload with
conditionadded in v15.03
AddCsp(string, params string[])
Add a CSP rule where you also specify the name. Best check the CSP Guide.
For an example, see Coded CSP
string AddCsp(string name, params string[] values)
Parameters
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddCsp(...)
AddIcon(string, NoParamOrder, string, int, string)
Add an Icon header tag to the Page.
string AddIcon(string path, NoParamOrder noParamOrder = default, string rel = "", int size = 0, string type = null)
Parameters
pathstringPath to the image/icon file
noParamOrderNoParamOrderrelstringthe rel-text, default is 'icon'. common terms are also 'shortcut icon' or 'apple-touch-icon'
sizeintWill be used in size='#x#' tag; only relevant if you want to provide multiple separate sizes
typestringAn optional type. If not provided, will be auto-detected from known types or remain empty
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddIcon(...)
AddIconSet(string, NoParamOrder, object, IEnumerable<string>, IEnumerable<int>)
Add a set of icons to the page
string AddIconSet(string path, NoParamOrder noParamOrder = default, object favicon = null, IEnumerable<string> rels = null, IEnumerable<int> sizes = null)
Parameters
pathstringPath to the image/icon file
noParamOrderNoParamOrderfaviconobjectpath to favicon, default is '/favicon.ico'
relsIEnumerable<string>sizesIEnumerable<int>
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddIconSet(...)
AddJsonLd(object)
Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data
string AddJsonLd(object jsonObject)
Parameters
jsonObjectobjectA object which will be converted to JSON. We recommend using dictionaries to build the object.
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddJsonLd(...)
AddJsonLd(string)
Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data
string AddJsonLd(string jsonString)
Parameters
jsonStringstringA prepared JSON string
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddJsonLd(...)
AddMeta(string, string)
Add a standard meta header tag. You may also want to use AddOpenGraph(string, string) or AddJsonLd(string)
string AddMeta(string name, string content)
Parameters
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddMeta(...)
AddOpenGraph(string, string)
Add an open-graph header according to http://ogp.me/
string AddOpenGraph(string property, string content)
Parameters
propertystringOpen Graph property name, like title or image:width. 'og:' is automatically prefixed if not included
contentstringvalue of this property
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddOpenGraph(...)
AddToHead(string)
Add a tag to the header of the page Will simply not do anything if an error occurs, like if the page object doesn't exist
string AddToHead(string tag)
Parameters
tagstring
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddToHead(...)
AddToHead(IHtmlTag)
Add a RazorBlade Tag to the headers of the page Will simply not do anything if an error occurs, like if the page object doesn't exist
string AddToHead(IHtmlTag tag)
Parameters
tagIHtmlTag
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.AddToHead(...)
AssetAttributes(NoParamOrder, bool, int, string, bool)
Add common html attributes to a script or link tag to enable optimizations
and automatically whitelist in the Content Security Policy
IRawHtmlString AssetAttributes(NoParamOrder noParamOrder = default, bool optimize = true, int priority = 0, string position = null, bool whitelist = true)
Parameters
noParamOrderNoParamOrderoptimizeboolActivate optimize, default is true
priorityintOptional priority of optimization. Must be more than 100 to have an effect.
positionstringOptional position of the resource (
head,body,bottom)whitelistboolAutomatically add to CSP-whitelist. This uses a random key to protect against XSS.
Returns
- IRawHtmlString
The asset attributes in a format which will be preserved in HTML
Remarks
History: Created in 2sxc 13.10
SetBase(string)
Add a standard base header tag or replace it if one is already provided.
string SetBase(string url = null)
Parameters
urlstringthe optional url for the base tag - if null, will try to default to the real url for the current page
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.SetBase(...)
SetDescription(string, string)
Set the Page Description.
It will either try to replace the placeholder (second parameter)
or prefix it to the existing description (unless [original] is given).
See also the details with placeholder or [original] as explained on SetTitle(string, string)
string SetDescription(string value, string placeholder = null)
Parameters
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.SetDescription(...)
SetHttpStatus(int, string)
Set the page status code if possible (it will work in DNN, but probably not in Oqtane)
string SetHttpStatus(int statusCode, string message = null)
Parameters
statusCodeintAn HTTP status code like 404
messagestringMessage / Description text (optional) which would be included in the header
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.SetHttpStatus(...)
SetKeywords(string, string)
Set the Page Keywords.
It will either try to replace the placeholder (second parameter)
or prefix it to the existing keywords (unless [original] is given).
See also the details with placeholder or [original] as explained on SetTitle(string, string)
string SetKeywords(string value, string placeholder = null)
Parameters
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.SetKeywords(...)
SetTitle(string, string)
Set the Page Title. Behavior:
- By default it will prefix the new title -
SetTitle('My New Title - ')=My New Title - Blog - 2sxc.org - You can also use the new
[original]token likeSetTitle('[original] - My New Title')=Blog - 2sxc.org - My New Title - You can add a placeholder to the page-title and tell SetTitle what it is.
SetTitle('My New Title', '2sxc.org') =Blog - My New Title`
string SetTitle(string value, string placeholder = null)
Parameters
Returns
- string
Empty string, so it can be used on inline razor such as
@Kit.Page.SetTitle(...)
TurnOn(object, NoParamOrder, object, object, IEnumerable<object>, bool, bool?, string)
Turn on some javascript code when all requirements have been met. Uses turnOn.
Will automatically activate the feature and set hidden data on the page for the turnOn JS to pick up.
string TurnOn(object runOrSpecs, NoParamOrder noParamOrder = default, object require = null, object data = null, IEnumerable<object> args = null, bool condition = true, bool? noDuplicates = null, string addContext = null)
Parameters
runOrSpecsobject- either a run
stringlikewindow.myObject.myJs()(must always start with window) - or an object containing all the parameters which turnOn requires
- either a run
noParamOrderNoParamOrderrequireobjectoptional One or more requirements which must be met before the code starts. Can be one or many values and/or functions.
- a
stringsuch aswindow.myObjectorwindow.myObject.readyToStart() - an array of such strings
- a
dataobjectoptional any value such as a string, or an object - to pass into the run-command
argsIEnumerable<dynamic>optional array of values to pass to the run function (new v18.00)
conditionbooloptional condition when this should happen - if false, it won't add anything (new v16.02)
noDuplicatesbool?Will not add this turnOn if an identical one is already added to the page (new 16.05)
addContextstringoptional when
argsis used, the context is usually not needed or given. If you do need it, it can be merged with data (if that's also provided and is an object - so usedata) or added to the end of the args listend. (new v18.00)
Returns
- string
An empty string, just so you can use it directly in Razor like
@Kit.Page.TurnOn("...")
Remarks
- Added in v15.x
conditionadded in 16.02noDuplicatesadded in 16.05argsandaddContextadded in v18.0