I use Spark View Engine with nested master pages. I have Application.spark which defines the basic layout of the website. Then there are several other masters which themselves use Application.spark as master page (Default.spark, SinlgeColumn.spark, Gallery.spark, …)
If no master page is specified in a view file, then automatically Application.spark is choosen by the Spark View Engine. Since almost all my pages use “Default.spark” as master, is there a way to configure this globally?
The other possibilities would be:
-
Set the master in each spark file individually
<use master="Default" />. But that’s really annoying. -
Rename my master files (Default.spark <-> Application.spark) but that really doesn’t make any sense in naming.
There are two ways to solve your issue:
Less Work
With any
ActionResult, you can simply add a second parameter to the return statement to specify the name of the master to use:the first parameter name is the view and the second signifies a master page override…but that does mean you need to repeat it everywhere, and this isn’t much better than what you had before.
More Work
The way that Spark locates the master page to use is via the following code in the framework:
Notice the hardcoded
Application.sparkin there – that’s a Spark convention. What it seems that you want to do is override this method and put something like this in instead:Then it will find your
Default.sparkbefore it findsApplication.sparkor you could get rid of theApplication.sparkentirely if it doesn’t ring true for you and you prefer your conventions…In order to override this, all you need to do is create a class that inherits from
Spark.Web.Mvc.DefaultDescriptorBuilderand override that method mentioned above and use it when you register the view engine like so:This now means that you can now direct where Spark should look for the Master views and what the names will be.
Hope that helps,
All the best,
RobertTheGrey