#3 Use PageService.Activate to enable features, Css and Js
Settings in 2sxc 🆕 in 12.03
Settings allow your code to use predefined settings across all apps and sites.
And they allow you to overide a setting at any level of the application.
You can read more about the settings in the docs 📕.
Use PageService.Activate to enable Features and Load JS/CSS
2sxc 12.04 helps with many advanced challenges like these:
- Make sure that certain scripts are only loaded once (like jQuery or FancyBox)
- Make sure that all apps use the same version of these scripts
- Starting things in the right order
Simple Example
The following example will tell the page that fancybox4
is required - which will automatically apply a lightbox to the image below.
It uses the WebResources
as configured in the Settings. By default, fancybox4 is already defined, but you can overide this or create your own WebResource definitions.
#3 Use PageService.Activate to enable features, Css and Js
@inherits Custom.Hybrid.Razor14
<!-- unimportant stuff, hidden -->
<hr>
Use PageService.Activate to enable... <!-- unimportant stuff, hidden -->
@{
Kit.Page.Activate("fancybox4");
Kit.Page.Activate("fancybox4"); // even if called multiple times, it will only be activated once
var imgUrl = App.Path + "/settings/demo-banner.png";
}
<a data-fancybox='gallery' href="@imgUrl">
<img loading="lazy" src="@Link.Image(imgUrl, width: 200, height: 200)">
</a>
<!-- unimportant stuff, hidden -->