2

I know that sitecore mvc dos't support RenderSection.

Is it any way to emulate it with Sitecore MVC ?

I just would like to have only required scripts for specific page.

Of course I can split it to 2 files and to View Rendering but it is seems not good way.

Liam
  • 27,717
  • 28
  • 128
  • 190
Arbejdsglæde
  • 13,670
  • 26
  • 78
  • 144

2 Answers2

3

This is not something that you may do easily. It is all about creating appropriate html helpers for that. Here is previous StackOverflow question describing how to implement that:

Using sections in Editor/Display templates

Also this article may help you as well:

http://tomkamphuis.blogspot.co.uk/2013/04/sitecore-and-mvc-rendersections.html

Community
  • 1
  • 1
Martin Miles
  • 2,086
  • 14
  • 18
2

What I did to solve this issue was to create add the following Placeholder in my main layout page (for me, at the end of the Javascript script tags)...

@Html.Sitecore().Placeholder("javascript")

Next add a Sitecore View Rendering that contains the Javascript...

@using Sitecore.Mvc
@using Sitecore.Mvc.Presentation
@model RenderingModel
<script>
    $(function () {
        // your javascript
    });
</script>

This rendering then gets added to the Design Layout of the content item assigning it to the placeholder "javascript".

As a beginner with Sitecore, I'd be interested what others thought of this solution.

spaceduk
  • 115
  • 1
  • 10
  • Yeah this is a simple way of doing it but would it be possible to do the same from let say another rendering? so imagine you want to create a rendering that does X and in that rendering you would want to have some javascript injected in the placeholder javascript? – Egli Becerra Feb 09 '20 at 07:06