Ways to pass variables into a $S script - Tamberra
Here at Tamberra, we see ourselves as professional digital problem solvers. We love a good mystery and that is what your project might be at this stage… a mystery. Who, what, where, when, why – these are all questions that we can help you answer.
Tampa, Web Development, Web Developers, Web Applications, Tampa Bay, Programmers, Newspaper Web Developer
post-template-default,single,single-post,postid-6002,single-format-standard,do-etfw,ajax_fade,page_not_loaded,,vertical_menu_enabled,side_area_uncovered_from_content,qode-theme-ver-7.5,wpb-js-composer js-comp-ver-5.1,vc_responsive

Ways to pass variables into a $S script

Ways to pass variables to a $S script.

21 Oct Ways to pass variables into a $S script

I try to stay active in the comments sections on Saxotech’s wiki. Whenever I learn something new or find something in the docs that didn’t work exactly right, I post it in the comments. I appreciate when other developers in the Saxotech/Newscycle community do this, so I try to keep an active conversation going there. I also add myself as a follower/watcher on pages I use often so I get an email notification when someone else adds a comment. Which leads me to the point of this week’s blog post.

Has anyone found a way to pass another variable to $S (Runs a script, which name is given as the input parameter.) besides the tag contents?

Sarah Stapleton-Gray

Sarah Stapleton-Gray with the Bay Area News Group posted a question on the object script docs page asking how to pass variables into a $S script. This is a great question that doesn’t have clear documentation. This blog post is an answer to that question.

I’ll describe 3 possible ways to pass variables to a $S script:

  1. Set custom variables inside object file calling the $S script
  2. Static localdata.ini variables
  3. Use Custom Tag Paramaters (only cce and newslist)

1. Set custom variables inside object file calling the $S script

A $S script can access all variables inside the object file that contains the $S call. Simply create a custom variable inside the object file, then reference that variable in the script. This is the solution that worked for Sarah.

I created some sample files to illustrate how this works.

Create a template calling your pbs tag and the subsequent object files. I used a newslist listing our blogs in this example.

Inside the newsItem99.pbo object file, we set two custom variables:

  • <%?substrlen1=200%>
  • <%?substrlen2=500%>

And then we call the script on the <%counter%> variable. It doesn’t quite matter in this case which variable we use to call the script.

Inside the script we can access the custom variables we created in the object file by using the SOSE GetVar method.

You can see this exact code running here: http://www.tamberra.com/section/scripttest

2. Static localdata.ini variables

You can set static variables inside localdata.ini and reference them in your script using the same SOSE GetVar method as referenced above.

Simply create a static variable inside localdata.ini.

And then reference it in your script file.

3. Use Custom Tag Paramaters (only cce and newslist)

The newslist and cce tags allow you to reference tag paramaters in the object files by using the variable <%tagparamXXXX%> where XXXX is the name of the parameter. I use this feature to my advantage to pass in values I need to use in the object files. This would also work for the $S script.

I pass in two parameters that are custom for me, substrlen and stubstrlen2:

Using similar object files as the first solution above, except we reference the custom tag parameters we passed into the pbs tag:

And then in the script, we get the variables using the SOSE GetVar method:

Have you passed variables into a $S called script in an interesting way? Share with us how you did it in the comments below. Any questions about what we did here? We’d like to hear from you!

Stacey Jenkins

Stacey Jenkins

Stacey has 15+ years of project implementations under her belt. From very large to very small, she has managed, analyzed, built, and tested systems and then trained teams how to use them. Specifics are on her linkedin, but at the end of the day, Stacey enjoys building things that give real value to the business at hand. She loves this stuff.
Stacey Jenkins