Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello everyone,
I'm making a macro that creates a gallery and I want to build a JavaScript block based on macro paramters for different options. In XSLT I would do it like this:
<xsl:variable name="initstr"> <xsl:text> $('#</xsl:text><xsl:value-of select="$galleryId"/><xsl:text>').royalSlider({ fullscreen:{ enabled:derpProof(</xsl:text><xsl:value-of select="$fullScreen"/><xsl:text>), nativeFS: true }, fadeinLoadedSlide: true, controlNavigation: 'thumbnails', thumbs:{ orientation: '</xsl:text><xsl:value-of select="$orientation"/><xsl:text>' }, autoScaleSlider:derpProof(</xsl:text><xsl:value-of select="$autoScale"/><xsl:text>), autoScaleSliderWidth:</xsl:text><xsl:value-of select="$galleryWidth"/><xsl:text>, autoScaleSliderHeight:</xsl:text><xsl:value-of select="$galleryHeight"/><xsl:text>, loop:derpProof(</xsl:text><xsl:value-of select="$autoLoop"/><xsl:text>), numImagesToPreload:4, arrowsNav: derpProof(</xsl:text><xsl:value-of select="$showArrows"/><xsl:text>), arrowsNavAutohide: true, arrowsNavHideOnTouch: true, keyboardNavEnabled: true }); }); </xsl:text> </xsl:variable>
<xsl:value-of select="umbraco.library:RegisterClientScriptBlock('RoyalInit', $initstr, 'True')" disable-output-escaping="yes"/>
How would I go about implementing this into razor?
Thanks -Brett
Found a way to do it but its messy having to double all the { and } to escape them. For those interested:
string scriptBlock = String.Format( @" $(document).ready(function(){{ $('#{0}').royalSlider({{ fullscreen:{{ enabled:{1}, nativeFS: true }}, fadeinLoadedSlide: true, controlNavigation: 'thumbnails', thumbs:{{ orientation: '{2}' }}, autoScaleSlider:{3}, autoScaleSliderWidth:{4}, autoScaleSliderHeight:{5}, loop:{6}, numImagesToPreload:4, arrowsNav:{7}, arrowsNavAutohide: true, arrowsNavHideOnTouch: true, keyboardNavEnabled: true }}); }});", @Parameter.galleryId, @Parameter.fullScreen, @Parameter.orientation, @Parameter.autoScale, @Parameter.autoScaleWidth, @Parameter.autoScaleHeight, @Parameter.loop, @Parameter.showArrows);
If anyone knows a better way, please post!
Thanks.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
RegisterClientScriptBlock: How to build a JavaScript block from variables?
Hello everyone,
I'm making a macro that creates a gallery and I want to build a JavaScript block based on macro paramters for different options. In XSLT I would do it like this:
How would I go about implementing this into razor?
Thanks -Brett
Found a way to do it but its messy having to double all the { and } to escape them. For those interested:
If anyone knows a better way, please post!
Thanks.
is working on a reply...