Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 05:32:58 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155544 Posts in 21714 Topics by 7736 Members
Latest Member: chris85
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Droplet variables in template  (Read 210 times)
washoc

Offline Offline

Posts: 17


« on: April 20, 2011, 08:48:45 PM »

Hi,

I am using a droplet on a page, eg. [[dropletname?testvar=99]]

My droplet works fine and interprets testvar=99 to perform it's function.

What I'd like to know is if I can / how to get my TEMPLATE to recognise if each page uses the droplet, ie. whether testvar is set and its value, so I can echo the 99 back to the page using code in the template.

Basically, the droplet opens a <div> tag and I need to close this in the template if the droplet is used on a page, because there is other content in between. I know I could use another droplet, after the content in the middle on pages where the first droplet is used but this will become messy.

I therefore thought I would put an if (isset($testvar)) echo testvar, in the template but the template doesn't recognise the value from the droplet.

I have tried adding the variable to the session in the droplet code and calling the session variable from the template but the problem is that the session variable is created after the page has loaded, so it works if you refresh the page but not the first time you visit it.

Can anyone suggest a way around this? Either using PHP or changing the way WB processes droplets so that variables are passed to the page before the template is rendered?

Any help would be much appreciated. Thanks in advance.
Logged
washoc

Offline Offline

Posts: 17


« Reply #1 on: April 20, 2011, 10:00:38 PM »

After a lot of trial and error and re-reading the documentation I worked this out for myself.

In my template I added an HTML comment where the div should be closed if that page used the droplet in question. Then in the droplet, I used str_replace to replace the HTML comment with my closing div tag. eg:

Code:
$wb_page_data = str_replace('<!-- close-div-here-if-droplet-used -->','</div><!-- div-closed-here-because-droplet-used -->',$wb_page_data);

Hope that helps someone else!

Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!