开发者

Spark view engine - named content ignored with RenderAction

开发者 https://www.devze.com 2023-01-04 17:48 出处:网络
Application.spark: <html> <head> <use content=\"head\"/> </head> <body> <use content=\"view\"/>

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消