Generování XML+RSS, n atributy a content type

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Werkov
Člen | 17
+
0
-

Ahoj, chci generovat XML (konkrétně RSS) pomocí šablon v Nette, ale nějak se mi to nedaří. Poud vynechám onen řádek s contentType [3], tak získám neuzávorkovaný kód [1] (vypisuje chypu Parse error: syntax error, unexpected $end. Pokud tam contentType dám, tak mi zase nefungují n-atributy [2] a výpis výsledku skončí za tím title v obrázu.

Je to nějaká moje chyba nebo Nette?

Ještě poznamenám, že to je šablona pro komponentu, kterou pak vykresluji v šabloně stránky, kde je jen {control rssGenerator}.

Díky.


[1]

<?php //netteCache[01]000405a:2:{s:4:"time";s:21:"0.08220800 1303756028";s:9:"callbacks";a:2:{i:0;a:3:{i:0;a:2:{i:0;s:19:"Nette\Caching\Cache";i:1;s:9:"checkFile";}i:1;s:83:"/media/data/Michal/Web/OOB/dev/src/libs/FeedUtils/FeedGenerator/templates/rss.latte";i:2;i:1303756023;}i:1;a:3:{i:0;a:2:{i:0;s:19:"Nette\Caching\Cache";i:1;s:10:"checkConst";}i:1;s:25:"Nette\Framework::REVISION";i:2;s:30:"bb2b723 released on 2011-02-06";}}}?><?php

// source file: /var/www/dev/src/libs/FeedUtils/FeedGenerator/templates/rss.latte

?><?php
$_l = Nette\Templates\LatteMacros::initRuntime($template, NULL, '19vd49s4zf'); unset($_extends);

if (isset($presenter, $control) && $presenter->isAjax() && $control->isControlInvalid()) {
	return Nette\Templates\LatteMacros::renderSnippets($control, $_l, get_defined_vars());
}
echo '<' . '?xml version="1.0" encoding="utf-8"?>' ?>

<rss version="2.0">
   <channel>
      <title><?php echo Nette\Templates\TemplateHelpers::escapeHtml($title) ?></title>
      <link /><?php echo Nette\Templates\TemplateHelpers::escapeHtml($URL) ?></link>
      <description><?php echo Nette\Templates\TemplateHelpers::escapeHtml($description) ?></description>
      <language><?php echo Nette\Templates\TemplateHelpers::escapeHtml($language) ?></language>
      <pubDate><?php echo Nette\Templates\TemplateHelpers::escapeHtml($template->date($date, \DateTime::RSS)) ?></pubDate>
      <lastBuildDate><?php echo Nette\Templates\TemplateHelpers::escapeHtml($template->date($date, \DateTime::RSS)) ?></lastBuildDate><?php if ($editor): ?>
      <managingEditor><?php echo Nette\Templates\TemplateHelpers::escapeHtml($editor) ?></managingEditor>
<?php endif ;if ($webmaster): ?>
      <webMaster><?php echo Nette\Templates\TemplateHelpers::escapeHtml($webmaster) ?></webMaster>
<?php endif ;if ($image): ?>
      <image>

	 <title><?php echo Nette\Templates\TemplateHelpers::escapeHtml($image->title) ?></title>
	 <url><?php echo Nette\Templates\TemplateHelpers::escapeHtml($image->url) ?></url>
	 <link /><?php echo Nette\Templates\TemplateHelpers::escapeHtml($image->link) ?></link><?php if ($image->width): ?>
	 <width><?php echo Nette\Templates\TemplateHelpers::escapeHtml($image->width) ?></width>
<?php endif ;if ($image->height): ?>
	 <height><?php echo Nette\Templates\TemplateHelpers::escapeHtml($image->height) ?></height><?php endif ?>krusad
      </image>
<?php foreach ($iterator = $_l->its[] = new Nette\SmartCachingIterator($items) as $item): ?>
      <item><?php if ($item->id): ?>
	 <guid><?php echo Nette\Templates\TemplateHelpers::escapeHtml($item->id) ?></guid>
<?php endif ;if ($item->name): ?>
	 <title><?php echo Nette\Templates\TemplateHelpers::escapeHtml($item->name) ?></title>
<?php endif ;if ($item->URL): ?>
	 <link /><?php endif ;echo Nette\Templates\TemplateHelpers::escapeHtml($item->URL) ?></link><?php if ($item->description): ?>
	 <description><?php echo Nette\Templates\TemplateHelpers::escapeHtml($item->description) ?></description>
<?php endif ;if ($item->datetime): ?>
	 <pubDate><?php echo Nette\Templates\TemplateHelpers::escapeHtml($template->date($item->datetime, \DateTime::RSS)) ?></pubDate>
<?php endif ;if ($item->author): ?>
	 <author><?php echo Nette\Templates\TemplateHelpers::escapeHtml($item->author) ?></author>
<?php endif ?>
      </item>
<?php endforeach; array_pop($_l->its); $iterator = end($_l->its) ?>
   </channel>
</rss>

[2]

<?php //netteCache[01]000405a:2:{s:4:"time";s:21:"0.85684500 1303756127";s:9:"callbacks";a:2:{i:0;a:3:{i:0;a:2:{i:0;s:19:"Nette\Caching\Cache";i:1;s:9:"checkFile";}i:1;s:83:"/media/data/Michal/Web/OOB/dev/src/libs/FeedUtils/FeedGenerator/templates/rss.latte";i:2;i:1303756120;}i:1;a:3:{i:0;a:2:{i:0;s:19:"Nette\Caching\Cache";i:1;s:10:"checkConst";}i:1;s:25:"Nette\Framework::REVISION";i:2;s:30:"bb2b723 released on 2011-02-06";}}}?><?php

// source file: /var/www/dev/src/libs/FeedUtils/FeedGenerator/templates/rss.latte

?><?php
$_l = Nette\Templates\LatteMacros::initRuntime($template, NULL, 'oinfn8ioqh'); unset($_extends);

if (isset($presenter, $control) && $presenter->isAjax() && $control->isControlInvalid()) {
	return Nette\Templates\LatteMacros::renderSnippets($control, $_l, get_defined_vars());
}
Nette\Environment::getHttpResponse()->setHeader("Content-Type", "application/xml; charset=utf-8") ;echo '<' . '?xml version="1.0" encoding="utf-8"?>' ?>

<rss version="2.0">
   <channel>
      <title><?php echo Nette\Templates\TemplateHelpers::escapeXml($title) ?></title>
      <link><?php echo Nette\Templates\TemplateHelpers::escapeXml($URL) ?></link>
      <description><?php echo Nette\Templates\TemplateHelpers::escapeXml($description) ?></description>
      <language><?php echo Nette\Templates\TemplateHelpers::escapeXml($language) ?></language>
      <pubDate><?php echo Nette\Templates\TemplateHelpers::escapeXml($template->date($date, \DateTime::RSS)) ?></pubDate>
      <lastBuildDate><?php echo Nette\Templates\TemplateHelpers::escapeXml($template->date($date, \DateTime::RSS)) ?></lastBuildDate>
      <managingEditor n:if="$editor"><?php echo Nette\Templates\TemplateHelpers::escapeXml($editor) ?></managingEditor>
      <webMaster n:if="$webmaster"><?php echo Nette\Templates\TemplateHelpers::escapeXml($webmaster) ?></webMaster>
      <image n:if="$image">
	 <title><?php echo Nette\Templates\TemplateHelpers::escapeXml($image->title) ?></title>
	 <url><?php echo Nette\Templates\TemplateHelpers::escapeXml($image->url) ?></url>
	 <link><?php echo Nette\Templates\TemplateHelpers::escapeXml($image->link) ?></link>
	 <width n:if="$image->width"><?php echo Nette\Templates\TemplateHelpers::escapeXml($image->width) ?></width>
	 <height n:if="$image->height"><?php echo Nette\Templates\TemplateHelpers::escapeXml($image->height) ?></height>krusad
      </image>
<?php foreach ($iterator = $_l->its[] = new Nette\SmartCachingIterator($items) as $item): ?>
      <item>
	 <guid n:if="$item->id"><?php echo Nette\Templates\TemplateHelpers::escapeXml($item->id) ?></guid>
	 <title n:if="$item->name"><?php echo Nette\Templates\TemplateHelpers::escapeXml($item->name) ?></title>
	 <link n:if="$item->URL"><?php echo Nette\Templates\TemplateHelpers::escapeXml($item->URL) ?></link>
	 <description n:if="$item->description"><?php echo Nette\Templates\TemplateHelpers::escapeXml($item->description) ?></description>
	 <pubDate n:if="$item->datetime"><?php echo Nette\Templates\TemplateHelpers::escapeXml($template->date($item->datetime, \DateTime::RSS)) ?></pubDate>
	 <author n:if="$item->author"><?php echo Nette\Templates\TemplateHelpers::escapeXml($item->author) ?></author>
      </item>
<?php endforeach; array_pop($_l->its); $iterator = end($_l->its) ?>
   </channel>
</rss>

[3]

{contentType application/xml; charset=utf-8}
{!='<' . '?xml version="1.0" encoding="utf-8"?>'}
<rss version="2.0">
   <channel>
      <title>{$title}</title>
      <link>{$URL}</link>
      <description>{$description}</description>
      <language>{$language}</language>
      <pubDate>{$date|date:\DateTime::RSS}</pubDate>
      <lastBuildDate>{$date|date:\DateTime::RSS}</lastBuildDate>
      <managingEditor n:if="$editor">{$editor}</managingEditor>
      <webMaster n:if="$webmaster">{$webmaster}</webMaster>
      <image n:if="$image">
	 <title>{$image->title}</title>
	 <url>{$image->url}</url>
	 <link>{$image->link}</link>
	 <width n:if="$image->width">{$image->width}</width>
	 <height n:if="$image->height">{$image->height}</height>krusad
      </image>
{foreach $items as $item}
      <item>
	 <guid n:if="$item->id">{$item->id}</guid>
	 <title n:if="$item->name">{$item->name}</title>
	 <link n:if="$item->URL">{$item->URL}</link>
	 <description n:if="$item->description">{$item->description}</description>
	 <pubDate n:if="$item->datetime">{$item->datetime|date:\DateTime::RSS}</pubDate>
	 <author n:if="$item->author">{$item->author}</author>
      </item>
{/foreach}
   </channel>
</rss>

Editoval Werkov (25. 4. 2011 20:38)

Werkov
Člen | 17
+
0
-

Tak jsem si s tím hrál a objevil jsem tohle podivné chování. Když tam dám uzavírací tag [1] (s lomítkem), tak se to zblázní a v kompilované šabloně se neudělá endif od toho if($image). Bez uzavíracího tagu [2] se to přeloží v pořádku.

Dělá mi to ve verzi, kterou jsem si právě stáhl (Nette Framework 2.0-dev (revision 539fdec released on 2011–04–13)) i v asi dva měsíce staré (Nette Framework 2.0-dev (revision bb2b723 released on 2011–02–06)).

Myslím, že je to bug. Jestli ne, tak mě nekdo poučte.


[1]

   <channel>
      <title>{$title}</title>
      <link>{$URL}</link>
      <description>{$description}</description>
      <image n:if="$image">
	 <title>{$image->title}</title>
	 <url>{$image->url}</url>
	 <lnk>s</l>
      </image>

{foreach $items as $item}
      <item>
	 <guid n:if="$item->id">{$item->id}</guid>
	 <title n:if="$item->name">{$item->name}</title>
	 <link n:if="$item->URL">{$item->URL}</link>
	 <description n:if="$item->desc">{$item->desc}</description>
	 <author n:if="$item->author">{$item->author}</author>
      </item>
{/foreach}
   </channel>

[2]

// ... vršek je stejný jako výše
	 <lnk>s{="</"}l>
      </image>

{foreach $items as $item}
// ... dál už je to stejné
   </channel>
spidy
Člen | 55
+
0
-

n atributy nefungují při content type xml, takže budeš muset psát místo n:if=„…“ normálně {if …}{/if}