Dynamically change the theme of a project with the sc_set_theme macro

Dynamically change the theme of a project with the sc_set_theme macro

Scriptcase provides macros, functions created by the developers of Scriptcase, which will assist in customizing applications as well as simplifying code editing at events.

In this article, we will see how to use the sc_set_theme macro in practice, to change the themes of your applications.

Using the sc_set_thema macro in Login

The macro changes the theme in the session, causing the change to be applied to all other applications until the session is finished or the theme changes again.

1. First, we must create a select field that must contain all the themes available for the change. The field name it's created is: set_theme

The listed themes must be previously added to the project.


The lookup method can be automatic, if there is a table with the name of the themes or manual, as in the example below.


 



2. After creating the field, at the beginning of the onValidate event, insert the macro code as in the image below:

Here is the code that should be added.

  1. // Change the theme of the project application
  2. $theme{set_theme};
  3. sc_set_theme($theme);
The macro accepts string sc_set_theme('ThemeName'); or verifiable location as in the example above.

Running the application

1. Run the login application and select a theme.


 

2. Click on ok, to execute the onValidity event, to change the theme.

The next application, in this example the form, will receive the selected theme.




How to keep the login with the default theme.

This macro changes the theme in the session, as previously informed. 

In this way, all applications will be displayed with the selected theme, including the login application.

 

To keep the login with the default theme, add the sc_set_theme macro to the onApplicationInit event stating the desired theme.

  1. sc_set_theme('BlueBerry');

If you would like the login theme to also be changed, just do not add the macro in the onApplicationInit event.


    • Related Articles

    • Using the sc_confirm macro

      In this article, see a practical example of using the sc_confirm macro. This macro can only be used on PHP buttons created in the toolbar of form and control applications, with the aim of confirming the action's excursion. See how to create a PHP ...
    • Using the sc_field_display macro

      To dynamically hide a field in this example, the macro sc_field_display is used, which is responsible for hiding or dynamically displaying a field or several. This macro has scope in the following events: In this example, it will be used within an ...
    • How to switch between themes dynamically through the Menu app

      In Scriptcase, it's possible to dynamically switch between themes by activating a Menu option, to enable that option, simply follow the steps below: Note The chosen project must have more than one theme selected, otherwise it will not be possible to ...
    • Adding Google Fonts to a Theme

      Watch our  Google Fonts video presentation 1 - Visit the link to access Google Fonts: https://fonts.google.com/ 2 -Select the desired font. 3 - Copy the link that is inside the tag. 4 - Go to Layout> Application Css (Themes). 5 - After that, click ...
    • How to add themes to an existing project

      In the project creation process, we must select the themes that will be part of the project. If you want to add new themes to previously created projects, follow the step by step below. Adding theme to the project 1 - First, add the new theme within ...