Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#256 2022-03-15 20:06:57
Re: smd_xml : extract data from XML feeds
Thank you, works like a charm.
Please one more thing if you can: I have tweaked smd_xml tag so that now it looks like this
fields="title, content, author->name, content|type"
and showtext form looks like this
<txp:if_variable name="thisfilter" value="text">
<dt>{title}<br />{author->name}</dt><dd>{content}</dd>
</txp:if_variable>
The smd_xml tag breaks. What am I doing wrong?
Thanks.
Offline
#257 2022-03-15 20:51:37
Re: smd_xml : extract data from XML feeds
Ah, this is subtle.
You have two things going on here. Firstly, you have correctly requested author->name – i.e. name beneath author – in the field attribute, but when you come to display it, the node name is only {name}. No distinction is made of the hierarchy when it comes to output.
Secondly, since you’re now using the plugin as a single (not container) tag, ontagstart and ontagend process their content immediately as soon as the nominated tag is encountered (at their start or end, respectively) when the feed is being parsed.
Look at the structure of your data feed and notice that the <content> node you are using as a trigger comes before the author node. This means that at the moment the ontagend form is invoked – when the first <content> tag ends – the author name is unknown; it hasn’t been read yet.
So you’ll need to go back to your <txp:smd_xml> tag and tweak your ontagend so it triggers when the author tag is done:
ontagend="showtext|author"
That should fix it.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#258 2022-03-16 07:50:38
Re: smd_xml : extract data from XML feeds
Thanks.
Unfortunately smd_xml tag is still broken.
I have tweaked it so that
ontagend="showtext|author"
and showtext form now looks like this
<txp:if_variable name="thisfilter" value="text">
<dt>{title}<br />{name}</dt><dd>{content}</dd>
</txp:if_variable>
but to no avail.
I have turned on debug mode, but no error message appears on the page.
Seems like extracting and outputting the author’s name is causing the issue. Any idea how to fix it?
Thanks.
Offline
#259 2022-03-16 07:55:35
Re: smd_xml : extract data from XML feeds
Weird. It worked for me using your exact setup. I’ll have to look later.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#260 2022-03-16 11:48:18
Re: smd_xml : extract data from XML feeds
No need for you to take a look. It was a Textile issue. Fixed it and now it’s working fine. Thanks.
Last edited by gilibaus (2022-03-16 11:48:58)
Offline
#261 2022-03-17 14:34:57
Re: smd_xml : extract data from XML feeds
From a syntax point of view, how do I handle replacement tags – in this case {im:rating} – in a javascript snippet? In my showtext form I have this code:
<script type="text/javascript">
...
var val = {im:rating};
...
</script>
and it does not seem to work. I guess brackets are the culprit, but I cannot find a solution. Thanks for any help.
Offline
#262 2022-03-17 14:55:19
Re: smd_xml : extract data from XML feeds
Does it work if you double or single quote the value?
var val = "{im:rating}";
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#263 2022-03-17 17:51:48
Re: smd_xml : extract data from XML feeds
Unfortunately no. In the xml feed, im:rating is an integer number between 1 and 5.
Offline
#264 2022-03-17 20:12:11
Re: smd_xml : extract data from XML feeds
gilibaus wrote #332933:
From a syntax point of view, how do I handle replacement tags – in this case {im:rating} – in a javascript snippet? In my
showtextform I have this code:
var val = {im:rating};
Long shot guess: Does {im:rating} work elsewhere outside the javascript block, i.e. will it output to the page on its own? If so, maybe try putting that in a txp:variable and then using the txp:variable in the javascript block? If not, your problem may lie elsewhere.
TXP Builders – finely-crafted code, design and txp
Offline
#265 2022-03-17 21:25:25
Re: smd_xml : extract data from XML feeds
Hmm, “it does not seem to work” is a bit vague, sorry. What do you actually see (or not)? And what do you expect to happen?
If I try the smd_xml tag I posted above, but tweak it to pull out the im:rating like this:
... fields="title, content, author->name, content|type, im:rating" ...
Then I can output the {im:rating} just fine to the page, and add it to JavaScript via:
<script>
var val = '{im:rating}';
</script>
in the form, which renders the integer between the apostrophes. However, please note that if you’re outputting JavaScript in this fashion, it will print the <script> tag and contents to the page for each record, so if you’re expecting to use the value of val in some code after the page has loaded, you’ll only get the very last value assigned to the variable, as it will overwrite all other values before it.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#266 2022-03-18 08:54:27
Re: smd_xml : extract data from XML feeds
Bloke wrote #332946:
so if you’re expecting to use the value of
valin some code after the page has loaded, you’ll only get the very last value assigned to the variable, as it will overwrite all other values before it.
I guess that’s the point, thanks for pointing it out. As a non-developer I make (many) mistakes, sorry for that. I double checked and the javascript block with var val = '{im:rating}' is actually working fine, no error messages in the browser console. What I am trying to do is retrieve the rating – i.e. {im:rating} – of each review in the feed and via css transform that number into something visually more appealing, like this ★★★★★. If you want you can see the result here. The very last value assigned to the variable is 5, and now all reviews show a 5-star rating, even though that does not correspond to reality as one review actually got 1 star. Do I get it right?
Offline
#267 2022-03-18 09:00:44
Re: smd_xml : extract data from XML feeds
Right that’s fine. At least the plugin is behaving. So what you really want is something like this in your show text form:
<dt>{title}
<br />
{name}
<span class="rating{im:rating}" />
</dt><dd>{content}</dd>
Then you can style rating1, rating5 etc to taste.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#268 2022-03-18 12:09:27
Re: smd_xml : extract data from XML feeds
Great thanks! It finally works.
Offline