Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Common script inside transformation View modes: 
User avatar
Certified Developer 12
Certified Developer 12
chetan2309-gmail - 11/4/2013 6:08:18 AM
   
Common script inside transformation
Hi All,

I'm using a custom script inside transformation inside <script> tags. Due to my limited knowledge I am copy pasting same transformation everywhere. IS there any way to define it somewhere and use it over and over.

Right now a small change in the script forces me to make changes at 5-6 different transformations.


Regards,
Chetan

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 11/4/2013 12:48:05 PM
   
RE:Common script inside transformation
When you say script, do you mean javascript or server side? If server side, create a method for it and simply call the method as you are now. If javascript, create a .js file and reference it in the pages you need.

User avatar
Certified Developer 12
Certified Developer 12
chetan2309-gmail - 11/4/2013 12:56:51 PM
   
RE:Common script inside transformation
Server side script. Can't I define at one place and use it everywhere?

Thanks

User avatar
Member
Member
eagleag - 11/4/2013 1:29:39 PM
   
RE:Common script inside transformation
Hi,

This might help you: http://devnet.kentico.com/docs/devguide/index.html?adding_custom_functions_to_transformations.htm


good lcuk

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 11/4/2013 3:36:39 PM
   
RE:Common script inside transformation
Yes you can. What eagleag suggests works although I typically create my own directory (same as the site code name) and namespace the code files. Then you reference your custom code in the transformation via namespace.class.function().

I choose creating my own classes because this way they will export with the site whereas the approach eagleag suggests won't. This is a huge benefit really. Especially if you want to providing the client with the best solution possible vs. just a quick fix.