Search

I have a custom extension used for interacting with an API. Using php:function I'm passing some data from the template to the extension and getting an array (converted to an XML document) as a response.

Using <xsl:value-of xmlns:php="http://php.net/xsl" select="php:function('foo','bar') /> in my page template I can retrieve the XML and it outputs just fine, the only issue is that it's a string. Is there any way that I can store this XML-in-the-form-of-a-string so that I can access it with XPath?

Hopefully that's clear, if not feel free to ask for elaboration where needed!

Ninja technique to wrap the value in an element node?

Make an xml utitlity that transforms the output before use in your main template maybe?

<result><xsl:value-of xmlns:php="http://php.net/xsl" select="php:function('foo','bar') /></result>

I may be way off, but not sure how the rest of your template is setup.

"Make an xml utitlity that transforms the output before use in your main template maybe?"

This was my first thought… but wouldn't that just be putting the string in a utility? The example provided would essentially give me:

<result>a string</result>

Ninja technique is something that I've heard about, but never looked into. Maybe this is the time?

Or maybe I should be approaching this whole thing differently, as I feel that using php:function is 'cheating' a bit anyway. I'm sure there's probably a cleaner way to get data from an API into a Symphony site.

There is, make a custom DS, or use the remote ds if it's a url based API.

In a custom DS, you would need to call your api in the __trigger function, and then you can use the XMLElement class, or DOMDocument to return xml if it comes back in another format.

I've never ventured into custom DS's - but practically speaking that does make sense, and fits the metaphor. It'd have to be custom though; I love the simplicity of remote DS's, but this is a pretty full-on API with authorization headers and post fields etc.

Cheers designermonkey. Any useful resources you can point me at that'd help me on my way to producing my first custom datasource?

(Started a new thread for help with the custom datasource, after having a look into it there were a lot of whooshing noises around my head: http://getsymphony.com/discuss/thread/99493/)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details