Im using the blog extension for TYPO3 7.6.23.
https://extensions.typo3.org/extension/blog/
I want to create a RSS-feed that shows the latest 3 blog articles.
I have a template Default.rss
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>{feed.title}</title>
<description>{feed.description}</description>
<language>{feed.language}</language>
<link>{feed.link}</link>
<lastBuildDate>{feed.date}</lastBuildDate>
<f:render section="content" />
</channel>
</rss>
And my setup TypoScript
blog_rss_posts = PAGE
blog_rss_posts {
typeNum = 202
10 = TEMPLATE
10.template = FILE
10.template.file = EXT:blog/Resources/Private/Layouts/Default.rss
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:text/xml;charset=utf-8
xhtml_cleaning = none
admPanel = 0
}
}
via
20 = TEXT
20 < tt_content.list.20.blog_posts
I get all my blog-posts.
The question is how can I fill my template with the right data?
I want to call domain.com/blog/?type=202 and get a RSS-Feed in XML.
What do I have to add in the TypoScript?
1st: 20 = TEXT is overwritten with the following 20 < tt_content.list.20.blog_posts, so: remove it.
2nd: with this copy 20 < tt_content.list.20.blog_posts you copied the base configuration for a plugin. as this plugin has no tt_content record all the configuration must be done in typoscript. You might use the TSOB, to explore possible parameters and set new values for the plugin.
Related
I'm trying to create an RSS document using R's XML package, but I'm running into trouble. Here is the code I'm using:
df <- data.frame(Labels <- c("Label_1"),
Values <- c("Value_1")
)
# CREATE XML FILE
doc = newXMLDoc()
root = newXMLNode("rss", doc = doc)
# WRITE XML NODES AND DATA
channel = newXMLNode("channel", parent = root)
title = newXMLNode("title","Metrics", parent = channel)
for (i in 1:nrow(df)){
prodNode = newXMLNode("Metric", parent = channel)
# APPEND TO PRODUCT NODE
newXMLNode("description", df$Labels[i], parent = prodNode)
newXMLNode("item", df$Values[i], parent = prodNode)
}
# OUTPUT XML CONTENT TO CONSOLE
print(doc)
# OUTPUT XML CONTENT TO FILE
saveXML(doc, file="RSS_Output.xml")
This gives me the following output, which doesn't work with RSS parsers because of, among other things, the wrong root node. Any ideas how to more cleanly generate an RSS file?
<?xml version="1.0"?>
<rss>
<channel>
<title>Metrics</title>
<Metric>
<description>Label_1</description>
<item>Value_1</item>
</Metric>
</channel>
</rss>
You mixed Metric and item nodes. According to the RSS spec (see https://www.w3schools.com/xml/xml_rss.asp) a channel contains 1 or more item elements
df <- data.frame(Labels <- c("Label_1"),
Values <- c("Value_1")
)
# CREATE XML FILE
doc = newXMLDoc()
root = newXMLNode("rss", doc = doc)
# WRITE XML NODES AND DATA
channel = newXMLNode("channel", parent = root)
title = newXMLNode("title","Metrics", parent = channel)
for (i in 1:nrow(df)){
prodNode = newXMLNode("item", parent = channel)
# APPEND TO PRODUCT NODE
newXMLNode("description", df$Labels[i], parent = prodNode)
newXMLNode("metric", df$Values[i], parent = prodNode)
}
# OUTPUT XML CONTENT TO CONSOLE
print(doc)
# OUTPUT XML CONTENT TO FILE
saveXML(doc, file="RSS_Output.xml")
<?xml version="1.0"?>
<rss>
<channel>
<title>Metrics</title>
<item>
<description>Label_1</description>
<metric>Value_1</metric>
</item>
</channel>
</rss>
I modified my default rss feed items to include elemnts from custom fields. It now looks like this.
<item>
<title>Post Title</title>
<link>http://example.com/</link>
<pubDate>Sun, 22 Apr 2018 16:35:09 +0000</pubDate>
<dc:creator><![CDATA[lubandi]]></dc:creator>
<category><![CDATA[Bobi Wine]]></category>
<guid isPermaLink="false">http://example.com/</guid>
<description><![CDATA[Source: AUDIO LAD]]></description>
<field>Custom field value here</field>
</item>
I have failed to figure out how to read the value for "field". I am using the default SimplePie to read all the other elements from the feed.
The SimplePie provides the function get_item_tags($namespace, $tag) , but i have tried and failed to get the value. This is the demo code from simple pie
$media_group = $item->get_item_tags('', 'group');
$media_content = $media_group[0]['child']['']['content'];
$file = $media_content[0]['attribs']['']['url'];
echo $file;
Any help will be greatly appreciated. Thank you.
EDIT: I modified the demo code like this for my situation but it is not working: It returns null
$media_group = $item->get_item_tags('', 'group');
$media_content = $media_group[0]['child']['']['field'];
$song_title = $media_content[0]['attribs']['']['field'];
echo $song_title;
I have a big XML file that I must read with XmlReader because it can not be loaded into memory. This XML is formatted in this way (is a reduced version):
<?xml version="1.0" encoding="windows-1252"?>
<Products>
<Product>
<Code>A14</Code>
<Name>Name1</Name>
<Manufacturer>
<Name>ManufacturerName</Name>
</Manufacturer>
<ProdCategories>
<ProdCategory>
<Code>015</Code>
<Name>ProdCategoryName</Name>
</ProdCategory>
</ProdCategories>
<Barcodes> <!-- note this line -->
</Barcodes>
</Product>
<Product>
<Code>A15</Code>
<Name>Name2</Name>
<Manufacturer>
<Name>ManufacturerName</Name>
</Manufacturer>
<ProdCategories>
<ProdCategory>
<Code>016</Code>
<Name>ProdCategoryName</Name>
</ProdCategory>
</ProdCategories>
<Barcodes>
<Barcode>
<Code>1234567890</Code> <!-- note this line -->
</Brcode>
</Barcodes>
</Product>
Note the <Barcode> <Code> elements: in the first <product> is missing.
This is the code that I use for read it and for put these data in a database:
XmlReader reader = XmlReader.Create("Products.xml");
reader.MoveToContent();
do
{
reader.ReadToFollowing("Code");
code = reader.ReadElementContentAsString();
reader.ReadToFollowing("Name");
Name = reader.ReadElementContentAsString();
reader.ReadToFollowing("Name");
ManufacturerName = reader.ReadElementContentAsString();
reader.ReadToFollowing("Code");
ProdCategoryCode = reader.ReadElementContentAsString();
reader.ReadToFollowing("Code");
BarcodeCode = reader.ReadElementContentAsString();
//Here I use "code", "Name", "ManufacturerName" variables to insert into a database
} while (reader.Read());
reader.Close();
All XML tags are present in all products except the <Barcodes> childs (<Barcode><Code>) that is present only on some product, then I cannot jump at next "code" with last ReadToFollowing because if not present I capture the first <product><code>.
I cant control XML output and cant modify it (is third-party).
There's a way to "ReadToFollowing('<Barcodes><Barcode><Code>')" so that I can specific what should seek and if there is not found I can jump it?
Thank you for your help, excuse my bad english.
I would suggest to pull each Product element into a tree model, using either https://msdn.microsoft.com/en-us/library/system.xml.linq.xnode.readfrom(v=vs.110).aspx or https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.readnode(v=vs.110).aspx, then you can use LINQ to XML query methods or XPath to read out the data of each Product in a safe way while maintaining a low memory footprint.
i want to insert a iframe via Typoscript and a Text-Object.
It works, when i want to add 1 variable to the URL-String.
MAIN.10 = TEXT
MAIN.10.data = TSFE:fe_user|user|username
MAIN.10.wrap = <iframe src="http://example.com/index.php?user=|"></iframe>
Now i have to include 2 variables in the URL-String, like that:
MAIN.10.wrap = <iframe src="http://example.com/index.php?user=|&email=|"></iframe>
How can i realise that? I'm testing and searching since hours, it would be great if there's somebody out there, who knows a solution.
Thanks for your help.
The easiest way would to use a coa for it:
MAIN.10 = COA
MAIN.10 {
10 = TEXT
10.value = <iframe src="http://example.com/index.php?user=
20 = TEXT
20.data = TSFE:fe_user|user|username
30 = TEXT
30.value = &email=
40 = TEXT
40.data = TSFE:fe_user|user|email
50 = TEXT
50.value = "></iframe>
}
You can of course use more sophisticated stdWrap constructs, but this is also quite readable.
Keep in mind that performing actions based on username and e-mail is a possible security issue. At least someone could expose users of your service if they guess both values correctly.
I am trying to figure out a way to update my web.config for different environments by updating the configSource for the appSettings element in the web.config.
Here are the way I know how to do it.
$xml.get_DocumentElement().appSettings.configSource = $replaced_test
The problem is that I want one base script where I can pass in different nodes to the script that I want to change and update but I am not sure how to do it.
For example, I want to be able to call a powershell script like this
changeWebConfig.ps1 nodeToChange newValueofNode
I hope this was clear enough.
This is the code I have now.
$webConfigPath = "C:\web.config"
# Get the content of the config file and cast it to XML
$xml = [xml](get-content $webConfigPath)
#this was the trick I had been looking for
$root = $xml.get_DocumentElement()."system.serviceModel".client.configSource = $replace
# Save it
$xml.Save($webConfigPath)
The problem I was having was the configuration node
I had to change it from
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
this to
<configuration>
I am not sure how to find the node with the configuration node in it's orginal state yet, but I'm getting closer.
function Set-ConfigAppSetting
([string]$PathToConfig=$(throw 'Configuration file is required'),
[string]$Key = $(throw 'No Key Specified'),
[string]$Value = $(throw 'No Value Specified'))
{
if (Test-Path $PathToConfig)
{
$x = [xml] (type $PathToConfig)
$node = $x.SelectSingleNode("//client[#configSource]")
$node.configSource = $Value
$x.Save($PathToConfig)
}
}
set-configappsetting "c:\web.config" CurrentTaxYear ".\private$\dinnernoworders" -confirm
Finally figured it out.
$root = $xml.get_DocumentElement().SelectSingleNode("//client[#configSource]").configSource = "test"
of course, I will replace "//client[#configSource]" with a variable so I can pass in different nodes as parameters to create my base script.
Im looking for a way to modify the code as well.
Here is a way you can view whats the node:
$path = 'c:\site\web.config'
$PublishState = (Select-Xml -Path $path -XPath "configuration/appSettings/add[#key='PublishState']/#value").Node.'#text'
$PublishState