Page 1 of 1

[SOLVED] Passing variables between pages

Posted: Fri Feb 13, 2009 2:05 pm
by nervino
Hi, I need to pass a variable between two pages.
The first page has a link that points to the second page passing a variable in the URL.
The second page has to display a flash object (zoomify) that needs a variable to be set (the path of the image to be displayed).


In the content of the first page I wrote:

Code: Select all

{cms_selflink page="player" text="Zoom Image" urlparam="&zoomifyImagePath=my_img_folder"}

The second page (the "player") is empty and has a separate template in which I put the code (in the content div):

Code: Select all

{object src='player.swf' height='600' width='100%' param='FlashVars::zoomifyImagePath=my_img_folder&zoomifyX=0&zoomifyY=0&zoomifyZoom=15&zoomifyToolbar=1&zoomifyNavWin=1&zoomifyNavWidth=75&zoomifyNavHeight=75&zoomifySlider=1'}
I tried, but I'm not able to get the zoomifyImagePath variable and assign it in the object tag of the template of the player. I also tried to put the object tag in the content of the player page itself, instead of the template, but the result is the same: I get errors...

In a word, I don't know how to get a variable and set it in an object tag.

I have read the smarty documentation about variables but I didn't find any solution.

Any help would be apreciated.

Thank you

Re: Passing variables between pages

Posted: Wed Feb 18, 2009 9:13 pm
by grailwebd
This page tells you how to write literal PHP:
http://forum.cmsmadesimple.org/index.ph ... l#msg21369

"$_GET", how to grab url variables in PHP:
http://www.w3schools.com/PHP/php_get.asp

- - -

Then you could just do something like this:

{php}
$object_html = 'codecodecode=' . $_GET('variable_name') .  'code';
echo $object_html;
{/php}

Hope that makes sense

Re: Passing variables between pages

Posted: Thu Feb 19, 2009 12:52 pm
by nervino
Thank you, it works!

I was using the cmsms object tag (http://dev.cmsmadesimple.org/projects/objecttag/) but I couldn't pass variables' values inside this tag. Is there a way to assign dynamic values, with GET, to a variable inside a smarty's tag (inside curly braces)?

Re: Passing variables between pages

Posted: Thu Feb 19, 2009 1:22 pm
by nhaack
Sure, you can access get parameter values very conveniently with smarty:

{$smarty.get.PARAMETERNAME}

You might want to check if a value exists and then pass that to the plug-in/module:

Code: Select all


{if $smarty.get.myparam}
{assign var=myparam value=$smarty.get.myparam}
{else}
{assign var=myparam value='my default value'}
{/if}

{module xyz param=$myparam}

This is just a quick moch-up not tested... but it should work somehow like that and give you the rough idea.

Best
Nils

Re: Passing variables between pages

Posted: Thu Feb 19, 2009 2:12 pm
by nervino
I need to send some data to flash via flashvars, and I tried to use the "object tag" (http://forum.cmsmadesimple.org/index.php?topic=23847.0)

I tried:

Code: Select all

{if $smarty.get.zoomifyImagePath}
{assign var=flashvars value=$smarty.get.zoomifyImagePath}
{else}
{assign var=flashvars value='my default value'}
{/if}

{object src='player.swf' height='600' width='100%' param='FlashVars::$flashvars'}
This code output:

Code: Select all

<object  type="application/x-shockwave-flash" data="player.swf" width="100%" height="600">
<param name="movie" value="player.swf" />
<param name="FlashVars" value="$flashvars" />
</object>
I should have something like this in my player page:

Code: Select all

<param name="FlashVars" value="zoomifyImagePath=120-65-I-3_IX"/>
But if I write "zoomifyImagePath=$flashvars" in the code of the object tag I get an error.

I guess it's a problem with this object tag that uses the sintax:

Code: Select all

param='FlashVars::$flashvars|other_var::other_var_value|...'

Thanks!

Re: Passing variables between pages

Posted: Thu Feb 19, 2009 3:02 pm
by nhaack
mhh... I do not know the object tag very well, but I could imagine that something like this could work out:

assuming your are passing "120-65-I-3_IX" as the value of parameter "zoomifyImagePath":

Code: Select all


{if $smarty.get.zoomifyImagePath}
   {capture assign=myvar}zoomifyImagePath={$smarty.get.zoomifyImagePath}{capture}
{else}
   {capture assign=myvar}zoomifyImagePath=some_default_path{capture}
{/if}

{object src='player.swf' height='600' width='100%' param=$myvar}

What this does: you capture the complete string you need prior to the object tag and then pass it completely as a variable to the tag.

The underlying assumption is that you need "zoomifyImagePath=120-65-I-3_IX" as the string to hand to the plug-in... if it's different, you should be able to change the syntax accordingly.

Let me know how it turned out :)

Best
Nils


----
edit:

you could just place {$smarty.get.zoomifyImagePath} somewhere into the body of your template at first to see if the value is correctly passed to the other page. If you can't see the value of "zoomifyImagePath" the problem arised earlier.

Re: Passing variables between pages

Posted: Thu Feb 19, 2009 4:59 pm
by nervino
It works!!

I modified the code in this way:

{if $smarty.get.zoomifyImagePath}
   {capture assign=FlashVars}zoomifyImagePath={$smarty.get.zoomifyImagePath}{/capture}
{else}
   {capture assign=FlashVars}zoomifyImagePath=some_default_path{/capture}
{/if}

{object src='player.swf' height='600' width='100%' param=FlashVars::$FlashVars}

Thanks nhaack, you drove me in the right direction.

Re: Passing variables between pages

Posted: Thu Feb 19, 2009 8:15 pm
by nhaack
Nice to hear. Please put a [solved] in front of your first posts title.

And a little remark (don't know if you got what I meant ;D):

the second capture after the {else} needs a specific path. "some_default_path" is just a place holder for your very own real path you'd like to use as the default... but I guess you got that.

Best
Nils

Re: Passing variables between pages

Posted: Thu Feb 19, 2009 9:34 pm
by nervino
nhaack wrote: the second capture after the {else} needs a specific path. "some_default_path" is just a place holder for your very own real path you'd like to use as the default... but I guess you got that.
Oh yeah, I got it!  ;D