1

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.

2

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

1 Comment

now I need to pass this variable value to external js. and replace there variable value. actually I need to change image slider time interval should change manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.