2

Closed

Theme only rendered correctly once it has been set to current theme in the admin back end

description

Steps to reproduce:

1) Create a clean install of Orchard

2) Download and install any theme from the gallery, but DO NOT set to current theme. In this instance I chose the Mango theme, but the issue is reproducible with any theme.

3) Create a class that implements IThemeSelector and selects the theme that you have just installed:
public class ThemeSelector : IThemeSelector
{
    private ThemeSelectorResult _requestCache;
    private bool _requestCached;

    public ThemeSelectorResult GetTheme(System.Web.Routing.RequestContext context)
    {
        if (_requestCached) { return _requestCache; }
        _requestCached = true;

        _requestCache = new ThemeSelectorResult { Priority = 10, ThemeName = "Mango" };
        return _requestCache;
    }
}
4) Browse to your site. Orchard will attempt to use the theme you supplied in the ThemeSelector class, but fails. See attached screenshot.

5) Go to the admin section, and set the theme you installed to the current theme. Now, change the current theme back to the original one.

6) Browse to your site, and the new theme should be rendered correctly, as expected.

Expected behavior:
The theme chosen by your ThemeSelector class should render correctly regardless of whether or not it has been previously set to current theme in the admin back end.

file attachments

Closed Feb 5, 2013 at 8:07 PM by sebastienros
Not a bug, themes need to be activated before being used. Like enabling a module.

comments

AimOrchard wrote Nov 21, 2012 at 8:52 AM

What happens if you just 'enable' the alternative theme instead of temporarily making it the current theme?

paynecrl97 wrote Nov 21, 2012 at 9:52 AM

If you enable the alternative theme in the admin back end by clicking 'Set current', then the theme works as expected.

In fact- if you then disable the theme by setting another one to the current theme, and then temporarily make the alternative theme the current one, it works as expected.

It appears that by clicking 'Set current', some sort of initialisation of the theme may be occuring and that this initialisation is required before the theme can be properly rendered.

paynecrl97 wrote Nov 21, 2012 at 9:52 AM

This also happens if you create a recipe that uses a theme that is installed, but has not previously been set to the current theme in the admin back end.

paynecrl97 wrote Nov 21, 2012 at 11:27 AM

I've noticed that the Activate method in AdminController in Orchard.Themes.Controllers calls IThemeService.EnableThemeFeatures("themeName").

This appears to be what is required to "activate" a theme.

Could this be moved to Orchard.Themes.ThemeManager.GetRequestTheme? Or is it too expensive to be called on every page load? Is there a method available that could check to see if a feature/theme has been previously enabled?