This project is read-only.

OrchardFeature "attribute" for templates

Topics: Core, Writing modules, Writing themes
Mar 24, 2012 at 8:20 PM

I just had the following idea: what if templates also could tell which feature they belong to, just like class can with the OrchardFeature attribute? I can see a need for this when a module overrides shape templates: with a distinction like this there could be multiple features that contain shape overrides to be enabled separately.

What do you think?

Mar 25, 2012 at 2:40 AM

1. how would you do that?

2. it's taken a year before anyone noticed that it can't be done, and there is an easy workaround when it happens (add it to your theme)

so, feel free to file a bug and/or send a patch, but I would say this is Pri 4,000

Mar 25, 2012 at 10:16 AM

Not knowing about how Orchard discovers shapes, I only have non-educated ideas, like having conventional file names for this kind of distinction (like "Feature.[FeatureName].TemplateName.cshtm) or some file metadata elsewhere (even conventional comments in the template itself).

I've created one issue here, for further evaluation. I don't say this is something highly important but maybe an idea worth discussing and eventually, when there is nothing else to do, or the need for it grows, implementing.

Mar 26, 2012 at 6:54 PM

The reason of having the OrchardFeatureAttribute is to cut the number of classes being registered in Autofac - for performance reasons. If it wouldn't be there - every class in a module having a couple of features would get registered no matter if it belongs to a disabled feature or not. Unnecessary load.

For shapes - we don't necessarily need a thing like that because:

  • Shape table is constructed once and only gets refreshed when global changes happen (like a module gets enabled/disabled)
  • The actual compilation of the shape happens when it gets called first (correct me if I'm wrong), so if it's not being called then it's existence doesn't add any overhead besides a single entry in the shape table.
Mar 26, 2012 at 7:42 PM

This isn't about performance. What bugs me is that there is no option to bing shape templates to features, thus selectively enabling shape overrides. So if a modules has overrides for all kinds of shapes but I don't want to enable all of them (e.g. because I'm satisfied with the default ones) I have to override those overrides by copying the built-in templates to reverse the override :-).

Mar 27, 2012 at 6:16 AM

Wait, you can achieve that exact scenario by adding alternates to that shape. The feature from which you add the alternate can be turned on and off. You don't need this :)

Mar 27, 2012 at 8:46 PM

Wow, indeed, thank you!