1
votes

How Can I get sitecore value and replace the js variable with that value ? in asp.net

ex: Assume sitecore field value is 4 then I need to get this value to a variable and replace the js with this value.

1
This is done the same way as you will have to in regular ASP.NET application -> exampleHarsh Baid

1 Answers

4
votes

For example, if on the current item you have a field Title and you want to assign its value to a JavaScript variable, you can use this code:

<script type="text/javascript"> 
    var title= '@Sitecore.Context.Item["Title"]';
</script>

I tried it in an MVC solution and it works fine.

And for ASP.NET WebForms, try this:

<script type="text/javascript">
    var title = '<%= Sitecore.Context.Item["Title"] %>';
</script>