Jump to content
Sign in to follow this  
stanoliver

A little bit of xml

Recommended Posts

My aim is to output a very basic xml document which should be styled with a few css-styles.

<?xml version = "1.0"?>
<contact-info>
   <name>Donal Duck</name>
   <company>Superducks</company>
   <phone>(011) 123-4567</phone>
</contact-info>

How do I implement it with processwire?

Share this post


Link to post
Share on other sites

It really depends how your utilizing pages. For example:

<?php
header("Content-type: text/xml");

$people = $pages->find('template=person'); // or whatever your template is

$out = "<?xml version = \"1.0\"?>";
$out .= "<contact-info>";

foreach($people as $person) {
  $out .= "<name>" . person->title . "</name>"; // whatever field is storing the info
  $out .= "<company>" . person->company . "</company>"; // whatever field is storing the info
  $out .= "<phone>" . person->phone . "</phone>"; // whatever field is storing the info

}


$out .= "</contact-info>";
echo $out;

?>

The above would find all "people" and output them in contact info (well, everyone's info would be place inside the contact info tags). You could just move those tags inside the foreach loop if you needed each tag to have their own. Alternatively, you could use $pages->get() method to get a certain page (person. A little bit more information regarding your template structure could help us better give advice/pointers.

Edited by louisstephens
mistyped a few variables
  • Like 1

Share this post


Link to post
Share on other sites

@louisstephens Yes, your examples already helps. Do you know if the xml-syntax would also work with the new page meta or does page meta need json-syntax

Basicly I just looking for comfortable ways/ideas how to get data (even better data rows) out of html tables, csv-files, xml-files etc. and vice verca for outputting them in the frontend. Let's say I have a row in a csv-file with the entries '100','200','300' (representing prices: '100'->first price ...)

At last coming back to your example from above: How would I need to change your code from above to get an export to an .csv-file?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Greg Lumley
      Hi! In busy learning to know PW better I'm looking at existing code.
      I have Bitpoets Editorial Responsive Blog as example. While looking through the code I've just found this line in the blog-head.php 
      <link rel="stylesheet" href="<?= $config->urls->templates ?>assets/css/main.css?ts=<?= time() ?>" /> I hope it's not a stupid question but I've never seen this before...
      main.css?ts=<?= time() ?> I notice the main template is empty but of course renders on the front end.
      Using a timestamp really has me totally confused. Can someone explain it to me please. 
      Thank you! 
      Greg
    • By hellomoto
      I can't tell what's wrong; my local development version appears just fine, but I copy over the site files and db online and the homepage content is not being contained. This is what it should look like (same site in the same browser, running on my localhost): http://imgur.com/UFZFzrd
      What could be the problem here? Sorry to bring up something so irrelevant to PW here, I just know that you all are a valiant and helpful group, and no one on StackExchange seems to even know what I'm talking about.
      Thanks a lot.
    • By picarica
      so i just downloaded this template  and i uploaded it to my server made some .php changes so it would work and stuff but all the css-transitions or css-animations don't work. they just stop
      if you checked out the template all those buttons are smooth and really nice, bit when you check out my site all those animations are gone, why is that? is there some option i have to toggle? or is it normal? how do i fix it ?
    • By Mike Rockett
      Docs & Download: rockettpw/seo/markup-sitemap
      Modules Directory: MarkupSitemap
      Composer: rockett/sitemap
      MarkupSitemap is essentially an upgrade to MarkupSitemapXML by Pete. It adds multi-language support using the built-in LanguageSupportPageNames. Where multi-language pages are available, they are added to the sitemap by means of an alternate link in that page's <url>. Support for listing images in the sitemap on a page-by-page basis and using a sitemap stylesheet are also added.
      Example when using the built-in multi-language profile:
      <url> <loc>http://domain.local/about/</loc> <lastmod>2017-08-27T16:16:32+02:00</lastmod> <xhtml:link rel="alternate" hreflang="en" href="http://domain.local/en/about/"/> <xhtml:link rel="alternate" hreflang="de" href="http://domain.local/de/uber/"/> <xhtml:link rel="alternate" hreflang="fi" href="http://domain.local/fi/tietoja/"/> </url> It also uses a locally maintained fork of a sitemap package by Matthew Davies that assists in automating the process.
      The doesn't use the same sitemap_ignore field available in MarkupSitemapXML. Rather, it renders sitemap options fields in a Page's Settings tab. One of the fields is for excluding a Page from the sitemap, and another is for excluding its children. You can assign which templates get these config fields in the module's configuration (much like you would with MarkupSEO).
      Note that the two exclusion options are mutually exclusive at this point as there may be cases where you don't want to show a parent page, but only its children. Whilst unorthodox, I'm leaving the flexibility there. (The home page cannot be excluded from the sitemap, so the applicable exclusion fields won't be available there.)
      As of December 2017, you can also exclude templates from sitemap access altogether, whilst retaining their settings if previously configured.
      Sitemap also allows you to include images for each page at the template level, and you can disable image output at the page level.
      The module allows you to set the priority on a per-page basis (it's optional and will not be included if not set).
      Lastly, a stylesheet option has also been added. You can use the default one (enabled by default), or set your own.
      Note that if the module is uninstalled, any saved data on a per-page basis is removed. The same thing happens for a specific page when it is deleted after having been trashed.
          
    • By CareerTeam GmbH
      Hi there,
      We are an executive search agency based in Germany looking for a freelancer (2-5 days per week) supporting us with the development and design of our websites. The position will be located in Hamburg, Germany and it would be great if you are on short call. German language knowledge is mandatory. 
      You can reach me via email jobs@careerteam.de.
      Thank you!
      Regards
      Annemie
×
×
  • Create New...