Jump to content


Photo

Noob question about variables


  • Please log in to reply
4 replies to this topic

#1 displayname

displayname

    Etomite Forum Newbie

  • Member
  • 7 posts

Posted 30 September 2009 - 05:36 PM

Howdy,
I am using a snippet to output text chosen by a random number. Later on the same page, from within a different snippet I'd like to output more text based on the same random number of the earlier snippet. What's the easiest way to access/pass a variable from/to the second snippet, please?
Thanks :)

#2 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 30 September 2009 - 11:53 PM

There are several ways that you could tackle this task... One way would be to use a session variable to hold the random number for the duration of the script, or longer... Another method would be to create a class object variable (property), like $etomite->randomNumber, which you would assign in the first snippet and then read in subsequent snippets... When using something like the $etomite->randomNumber variable it will not be carried over into subsequent page loads...

Hope this helps... Welcome to the Etomite forums...

#3 Cris D.

Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts

Posted 03 October 2009 - 09:39 AM

I also use runSnippet to pass variables on to the next snippet by passing it in the $params.

eg:

$text=1;

$out = $etomite->runSnippet('otherSnippet', $params=array('getTextVariable'=>$text));

The $text variable will then be available in the otherSnippet snippet as a variable called $getTextVariable as if you had passed it in the snippet call.

Edited by Cris D., 03 October 2009 - 09:40 AM.


#4 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 03 October 2009 - 02:07 PM

The runSnippet() technique will only work for chaining snippets together and I use it extensively myself... If, however, the same information is needed elsewhere in the page template then my suggestions would be the solution...

#5 displayname

displayname

    Etomite Forum Newbie

  • Member
  • 7 posts

Posted 04 July 2010 - 09:16 PM

Well, it was long ago, but still: thank your for your friendly help! Snippet variables was the solution. :)
Sorry for being so late.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users