views:

22

answers:

1

Application.spark:

<html>
  <head>
    <use content="head"/>
  </head>
  <body>
    <use content="view"/>
  </body>
</html>

Index.spark:

# Html.RenderAction("Hello");    // This renders _Hello.spark

_Hello.spark:

<content name="head">
    <script src="/hello.js"></script>
</content>

<p>hello</p>

And head content of _Hello.spark is ignored. How can I make it included?

A: 

RenderAction renders partial view, which doesn't usually have master view (layout). You can try to specify master layout for the _Hello.spark but it will be rendered inside the partial result, not inside master view.

You can try to use <use file="_Hello.Spark" /> (or <Hello />) instead, this would hopefully render head content in the main master layout. But this requires _Hello.spark to be pure partial view, not action.

If you need RenderAction, you won't be able to modify your head content from there. RenderAction runs separately outside Spark at runtime, and merging head content is done by Spark at compile time.

You can use JavaScript to modify head content from the rendered action result.

Or, you can specify your script includes in the main view.

You can also put them into _HelloIncludes.spark and do <HelloIncludes /> - to avoid duplication of code.

queen3