0

Ok - so I have written this code to output values using JSP and set them as JS variables so I can pass them to my Google Analytics tracking code.

<dsp:droplet name="/atg/dynamo/droplet/ForEach">
            <dsp:param value="${CommerceItems}" name="array" />
            <dsp:param name="elementName" value="CommerceItem" />
            <dsp:oparam name="outputStart">var itemCatList ='</dsp:oparam>
            <dsp:oparam name="output"
                <dsp:getvalueof id="Category"param="CommerceItem.auxiliaryData.productRef.productWebType.productWebTypeDescription">${Category}|</dsp:getvalueof>
            </dsp:oparam>
            <dsp:oparam name="outputEnd">'; </dsp:oparam>
        </dsp:droplet>

Im not sure if this is the correct way to go about doing this - previously the values were set to hidden inputs - then JS is used to grab those values out. I was trying to eliminate the extra code.

Any issues with doing it this way?

1 Answer 1

1

No, although opinion is mixed on what the best way to expose variables into JS is.

I find the above non-obvious and difficult to read, however. If there was a way to consume JSON I might prefer that as opposed to building a pipe-delimited string, or I would wrap it up in a custom tag that abstracted all of this away so a casual reader wouldn't have to do any mental gymnastics.

Another option would be to build the delimited string in Java code and expose it directly.

Sign up to request clarification or add additional context in comments.

Comments

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.