Search code examples
phphtmlvariablesgettumblr

Define variable through iframe in HTML $_Get


I have a Tumblr site where I can edit the HTML and CSS. They have this variable which is called {Permalink} which refers to the current post's link.

Since PHP is not allowed, I had to host a script externally and put it in my site through an iframe. The problem is that the script contains this:

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="YOUR URL" num_posts="1" width="460"></fb:comments> 

where I would like to replace "YOUR URL" with {Permalink}. Since the PHP file is hosted externally it wouldn't work. So what I'm looking for is to put a undefined variable there, and define that variable through my iframe, like so:

<iframe src="my.php" width: "460" data-urlvariable: "{Permalink}"></iframe>

and in my .php file:

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="$_data-urlvariable" num_posts="1" width="460"></fb:comments> 

I figured the php GET method would do the job, but I'm not so sure how to use it in a <div><script>. So is there a way to define a variable within my tumblr site and put it in my externally hosted php file?

Anyway here's part of the .php file.

   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   </head>
   <body>
         <div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="YOUR URL" num_posts="1" width="460"></fb:comments>

         <div style="visibility:hidden">
         <?php

$STD_PATTERN = "<img src='@@userpicture@@'/><a href='@@userlink@@'>@@username@@</a> <BR> @@message@@ <BR> @@formatteddate@@<HR>";

/* PLEASE DON'T MODIFY THE CODE BELOW THIS COMMENT */
class SEO_FBComments {
    const GRAPH_COMMENTS_URL = "https://graph.facebook.com/comments/?ids=";

    private $pattern;
    private $pageUrl;

Solution

  • Maybe someone with more Tumblr experience can chime in here, but I’m pretty sure that the {Permalink} is being parsed by a Smarty (or similar) template engine. In this case, since the template variables (the words inside {}) are coming from the server side, there is no way to call them in an <iframe> hosted elsewhere.

    All is not lost however. You can grab the {Permalink} value with JavaScript (or jQuery) and save it as a client-side JavaScript variable, then pop that variable’s data into your PHP call in the <iframe>.