This project is read-only.

ShapeProvide OnDisplaying

Topics: Core, Writing themes
Aug 7, 2013 at 4:29 PM
I placed the below in my theme ( themeName > Code > ContentShapeProvider .cs). It fails to fire the OnDisplaying event. It fails no matter what Shape I refer to in he Describe method.

I build, rebuild etc, but it seems to have no effect. Anyone have any ideas? Is there a place this needs to be configured before it works, a special folder name, anything like that??

public class ContentShapeProvider : IShapeTableProvider
    public void Discover(ShapeTableBuilder builder)
        // Widget-MenuWidget    Widget__MenuWidget
            .OnDisplaying(displaying =>
                // some logic here...

Aug 7, 2013 at 9:50 PM
You probably forgot to add it to your theme's project file (do you have one?)
Aug 8, 2013 at 3:14 AM
Not sure what that is or if I have one. I did generate the theme using Orchard command line utils - though not sure if that mean I have one.

Is there any docs for this?
Aug 8, 2013 at 3:20 AM
Sorry, you simply meant the usual csproj file.

Just had a look at the Contoso theme, as I know it uses a ShapeTableProvider, and will copy what it does.

Thanks for the pointer...
Aug 8, 2013 at 3:21 AM
Theme Project file is just your everyday .csproj file. When you generate your theme, you can specify to create a .csproj file for your theme. If yor theme is called "MyTheme", look for a project file called "MyTheme.csproj". If it's not there in your module's root folder, you don't have one, but you can easily create on by regenerating your theme using the command line options available (refer to the docs for details). Make sure you move your existing theme to a new folder, from which you can copy back your files after regenerating the theme.
Aug 8, 2013 at 3:38 AM
Yep, just did that and got me a project file. Thanks for the tip.
Aug 8, 2013 at 4:15 AM
Edited Aug 8, 2013 at 4:21 AM
Ok, for future reference, steps required to get this to work were:

Create theme with Orchard command util as follows:
codegen theme ThemeNameHere /CreateProject:True
Reload the Orchard solution when prompted.

Find the project 'ThemeNameHere' and unload it so as to enable csproj file editing.

Right click your 'ThemeNameHere' project, and click 'Edit YourThemeName.csproj'.

Add the below item group to your csproj file:
    <Compile Include="Code\YourShapeProvider.cs" />
Reload your project. Build and launch - the ShapeTableProvider code should now fire as expected.

(To reiterate @sfmskywalker advice, make sure you move your existing theme to a new folder if you are doing this retrospectively to an existing theme, from which you can copy back your files after regenerating the theme)