Custom elements and Import polymer/polymer.html using PHP

593 views
Skip to first unread message

Romer Ventura

unread,
Oct 21, 2014, 1:03:01 PM10/21/14
to polym...@googlegroups.com
Hello,

I am having some issues creating some custom elements. I am trying to do:
my-element.html:
<link rel="import" href=<?php echo BaseUrl.'external/polymer/0.4.2/polymer/polymer.html';?>>

The above will not work I have to do:
<link rel="import" href="../../../../external/polymer/0.4.2/polymer/polymer.html">

On my index.php the php echo for the html import works, i am thinking it is because JS cant resolve the  "php echo" part...

Is what i am trying to do not possible, or are there any work around..?

Thanks.

Eric Bidelman

unread,
Oct 21, 2014, 2:22:03 PM10/21/14
to Romer Ventura, polymer-dev
Is PHP processing my-element.html? If it's not, than <?php echo ... ?> won't get interpreted and you'll be left with the literal string "<link rel="import" href=<?php echo BaseUrl.'external/polymer/0.4.2/polymer/polymer.html';?>>".

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/1d3d9332-2b58-4a85-a8c5-b901cf0e29a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Romer Ventura

unread,
Oct 21, 2014, 3:30:53 PM10/21/14
to polym...@googlegroups.com, rom...@gmail.com
Well it does depending on which file you are asking about.

I have my index.php with all my HTML, css, etc. On this index.php the <?php echo?> is getting processed. However, i created a folder "elements" where i have all my custom elements, but importing any polymer components with <?php echo  ?> from within "elements/my-custom-element.html" will fail. Error reported in the dev tools console is:

So i can see that the <?php echo ?> is not being interpreted. So i changed the file file extension from my-element.html to my-element.php and i get the same exact error, for some reason the php code is not getting interpreted..

Any ideas?

Thanks

Scott Miles

unread,
Oct 21, 2014, 6:53:15 PM10/21/14
to Romer Ventura, polymer-dev
 file extension from my-element.html to my-element.php

That should work. The point is that PHP is a server side tech that does it's thing before the file ever gets to the browser (or has anything to do with Polymer). When the server gets a request for *.php, it generally runs that file through PHP and lets PHP send whatever result it wants back to the client.

You can still support elements/*.html files, but you'd have to configure your server so it knows that requests for those files should go through the PHP parser.


Romer Ventura

unread,
Oct 21, 2014, 9:18:28 PM10/21/14
to Scott Miles, polymer-dev
Nope. That doesn't work.  I've tried it. I think it maybe because the HTML import is being picked up by platform.js 

If you look at the posted error it shows the beginning of the PHP tags and not being interpreted. 


--
Sent from Gmail Mobile

Scott Miles

unread,
Oct 22, 2014, 12:36:59 PM10/22/14
to Romer Ventura, polymer-dev
>> Nope. That doesn't work.  I've tried it

Yes, sorry, I did read that in your post, but I'm suggesting that it doesn't work because of some other misconfiguration.

>> I think it maybe because the HTML import is being picked up by platform.js 

It can't have anything to do with HTMLImports or platform.js, because those are client-side technologies and PHP is purely server-side. 

It's important that you fully understand that statement for you to be able to diagnose this problem. =P

>> If you look at the posted error it shows the beginning of the PHP tags and not being interpreted. 

The client sends some request to the server, the server sends back some data. What happens in the middle is invisible to the client (HTMLImports and/or platform.js in this case). It's the server's job to execute server-side tools like PHP and send the pre-processed data back to the client. It's in this last step that the PHP tags are converted, so this problem is server side (or the client is making requests in such a way that the server is not realizing PHP should be involved).

Romer Ventura

unread,
Oct 22, 2014, 1:05:42 PM10/22/14
to Scott Miles, polymer-dev
Exactly...!! 

HTMLImpost and platform.js read the information from the files and gets it back to the client side. The client then just reads that was provided by the import and platform.js. Everything else on PHP is getting interpreted except, for "<link rel="import" href=<?php echo BaseUrl.'external/polymer/0.4.2/polymer/polymer.html';?>>" being used when creating custom elements.

If there was a problem with the server interpreting PHP, then i would see the same behavior in all other uses of href=<?php echo.....?>

--
Thanks
Romer Ventura

Scott Miles

unread,
Oct 22, 2014, 1:09:24 PM10/22/14
to Romer Ventura, polymer-dev
You have it exactly backwards. Please read my message again. The client reads no files, it only gets data as transmitted from the server, *after* any work PHP would be able to do.

>> If there was a problem with the server interpreting PHP, then i would see the same behavior in all other uses of href=<?php echo.....?>

Not if the problem involves the server not sending certain requests to PHP for processing, then you have exactly the problem you are describing.

Scott
Reply all
Reply to author
Forward
0 new messages