Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hi,

I must have made a mistake somewhere.

I defined a variable from PHP with
Code: Select all
<cms:set priceglobal = "<cms:php>global $cost60d; echo $cost60d;</cms:php>" scope='global' />


I can display the variable within the same page with:
Code: Select all
<cms:show priceglobal />


BUT when I fetch the page's value from another page, I can't retrieve the variable 'priceglobal'.

Code: Select all
<cms:pages masterpage='reproductions_artiste.php' limit="10">
<g:price><cms:show priceglobal /></g:price>


What did I miss??
Hi,

You missed the fact that <cms:set> sets the variables in memory and these last only till the current page is executing. You navigate to a new page and all the previous variables are erased from memory and the script on the new page is given a blank slate to set its own variables.

So to access variables across page runs, we need to persist them somewhere other than the memory.
One place is the database - in fact, whenever you try using <cms:pages> to fetch variables from another page (as you are doing), you access all such values saved in the *database* - and these are your 'editable' regions.

Another place is the 'session' which appears to be the best location for your use-case.
For that please see viewtopic.php?f=5&t=7377 for a discussion on 'Session Variables'.

Hope this helps.
Thank you very much.

It still does not work, but at least it does something. I couldn't find an example of using it.

On the price snippet, I put:
Code: Select all
<cms:set_session name='pricegm' value=priceglobal />


Then when I invoke in the google_merchant.php page:
Code: Select all
<cms:get_session 'pricegm' />


It does not work. BUT, if I visit a product page, then reload google_merchant, it shows the price of the article on the product page to all articles in google_merchant listing.

It is like it does not execute the <php> that determines the price if the page is not loaded for real.
OK, nothing worked, so I simply recalculated each price individually with PHP on the fly, on the page.

Simple.

Thank you, anyway.
Paolo
I am glad you could find a work around Paolo.

As to why <cms:set_session> / <cms:get_session> did not work, I suspect it has to do again with the aggressive caching that is being deployed on your site (by Cloudflare, if I remember right?). As I found out in the last problem you reported, the caching makes it impossible to know when a PHP file (includes Couch tags) will get executed and when a previously saved static file will get served.
5 posts Page 1 of 1