Ideas for populating or altering an element display from a PHP Array


(Steve) #1

I’ve got an interactive map that allows (via no color Buttons) the means to link to a Cart to rent Cabanas.

We’re finding an issue in not being able to preload which are actually available based on a Date.

Question: I can poll the Database and know based on a pre-selected date which elements should be available. Are there any examples of Content being affected by known data when loading a Hype page?

Ideas are adding a class if an elementID is available in an array or the opposite assign a class of “disable” if not present in an array.

Any other ideas I should be considering from those that have needed similar data based display results?


(Jonathan Deutsch) #2

There are definitely examples on the forums with loading dynamic data with PHP (and JSON data), though I don’t think I found a canonical example in some searching myself. But I think you have the basic idea; my approach would be:

  1. Have PHP code in your .html file (renamed to .php) or in a separate URL that outputs a JavaScript object. This can be a global. (If in a separate URL, you’ll need to make an AJAX call and do your own assignment)
  2. Assign IDs or Class Names to the elements you want to toggle
  3. On Scene Load add a Run JavaScript action that examines the JSON object and then changes visibility of the elements or whatever else you want to do

(Mark Hunte) #3

Here is an example using the method of a public published to web google sheet.
The sheet should only be for public data.
See this post on how to set that up.

A sheet can be shared with people/team who are the only ones who can edit it. Don via the normal google share options.

You can see the sheet used in the example below here but I have turned editing off for obvious reasons.

cabTest.hype.zip (937.2 KB)

This is a quickly put together as I should be in bed… :grin:


(Steve) #4

Awesome! Thanks Jonathan and Mark!