Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Putting PHP in Harlowe?

I know you can insert normal HTML codes right into a passage in... pretty much any Twine 2 formats, yes? Is it possible to insert PHP code as well? I gave it a test go and the ?php part of the code got parsed out as something(?) so it didn't process right; I'm wondering if that's because it doesn't support the syntax or if I'm missing some sort of escape code.

(I did a bunch of searches and didn't find anyone asking about this, apologies if I missed it.)

Comments

  • PHP is a server side scripting language, as far as I know even if the Story Format's Javascript engine left the php related elements in the Passage currently being displayed the web-browser would not know what to do with those elements.

    But maybe someone else knows of a solution to client-side processing of embedded PHP elements.
  • Ahh, I hadn't thought about that part (that all the PHP code would have be executed when the server first loads the page). Which is important in the long run for what I'm trying to do, but...

    I've been looking at the resulting test page and the twine file and I suddenly to my chagrin recalled that ?text is a hook reference. So it's parsing the text as a hook reference when it generates the html file. Gah!

    I suppose it's possible to get the php to generate properly on initial load, if one could find a way to mark the ?php as not-Harlowe-code without ALSO marking it as not-HTML as `escaping` does. Which I think is probably never going to happen.

    Balderdash. Back to the drawing board. Thanks anyway, greyelf!
  • I suppose it's possible to get the php to generate properly on initial load
    The only reason the ?text is being treated as a hook is because the story HTML is not being processed as PHP by the web-server.

    Put another way:

    If the story HTML file is served from a web server that has PHP enabled (and configured to process the story HTML file) then the php related elements will be executed before the embedded Javascript engine starts up. This means that by the time the engine processes the Passage that contained the php elements those elements will no longer exist.
  • Hey InspectorCaracal!

    Did you find a way to include php in Harlowe? I would be very much interested in your findings, as I am looking for a way to enable visitors to rate paragraphs (using a php-based counter).
  • edited April 2016
    You could use JavaScript AJAX requests. It'd be somewhat of an advanced topic, though.

    This would, of course, require editing passage text without returns, due to AJAX's asynchronous nature. Additionally, the PHP files would have to be separate from the story text.
Sign In or Register to comment.