Macro inside an external JavaScript?

Ger Vang asked on July 11, 2014 15:22

Am I able to use Macro {$ResourceString$} inside an external JavaScript file? I know you can do this in a Web Part for "In-Line Javascript".

Recent Answers


Pavel Janečka answered on July 12, 2014 05:57

Hey Ger Vang,
I suggest you to store the macro value into the inline javascript variable. Then you can reference that variable from the external file of yours (just make sure you reference that variable AFTER being assigned to).

More advanced js techniques may apply as method I described is not the best option for greater maintainability. However if don't plan on heavy complicated javascript single page architecture, this approach might be as good as any other.

In my very personal opinion, I would not event recommend macro-like replacements in the source code files (your external JS code) as it would have a severe impact on the code readability and cleanliness.

I hope that helps,
Pavel

1 votesVote for this answer Mark as a Correct answer

Ger Vang answered on July 14, 2014 20:41

Yes, it makes sense not to put any macro inside an external JavaScript file because Kentico won't be able to render it. I think for now I'll just store the variable in-line and pass the resource string into a method.

Thanks Pavel.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.