Copy link to clipboard
Copied
I'm trying to create an Atom feed using cffeed (funny that all of the examples on the internet use RSS). If I leave out "content", the feed is created fine, but of course with no content. I have the following cfscript:
s.entry.content = StructNew();
s.entry.content.value = posts.post_body;
(s is the struct I'm passing to cffeed, entry is the array that contains all of my entries using index i)
But I get the following error:
content should be a Array.
So I go ahead and change it to this:
s.entry.content = ArrayNew(1);
s.entry.content[1] = posts.post_body;
And now I get this error:
content should be a Struct.
So which is it, ColdFusion? An array or a struct?
Copy link to clipboard
Copied
It was perhaps your intention to do something like this:
<!--- s is a struct, entry an array --->
<cfset s.entry = arrayNew(1)>
<!--- initialize each element in the entry array as a struct --->
<cfloop index="i">
<cfset s.entry=structNew()>
</cfloop>
<!--- content, title are keys in a struct --->
<cfset s.entry[1].content="content_1">
<cfset s.entry[2].content="content_2">
<cfset s.entry[3].content="content_3">
etc., etc.
<cfset s.entry[1].title="title_1">
<cfset s.entry[2].title="title_2">
<cfset s.entry[3].title="title_3">
etc., etc.
<!--- more generally, in a loop --->
<cfloop index="k"
<cfset s.entry
<cfset s.entry
etc., etc.
</cfloop>
Copy link to clipboard
Copied
Thanks, but just setting content equal to a string was the first thing I tried. I had:
for (i = 1; i <= posts.RecordCount; i++)
{
...
s.entry.content = posts.post_body;
...
}
And I get the error:
content should be a Array.
Copy link to clipboard
Copied
Then posts.post_body is probably an array!
Copy link to clipboard
Copied
posts.post_body is definitely a string, plus, even if I try the following:
s.entry.content = "My String";
I still get:
content should be a Array.
On the line in which the feed should be created.
Copy link to clipboard
Copied
Problem clear. What if we go back, and give it what it wants, like this
s.entry[1].content = ArrayNew(1);
s.entry[1].content[1].value = posts.post_body[1];
Copy link to clipboard
Copied
Thanks! It's working now!
When I tried the code you gave me, I got the following error:
However, this was easily fixed by doing the following:
s.entry.content = ArrayNew(1);
s.entry.content[1] = StructNew();
s.entry.content[1].value = posts.post_body;
Copy link to clipboard
Copied
Finally. Good for you! Mark that you've answered the question, for fellow developers searching for an answer to the same problem.
Copy link to clipboard
Copied
Hmm, you can't make your own post the correct answer?
Copy link to clipboard
Copied
That's true. I meant you should mark it as answered, which you've done.