Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#265 2022-03-17 21:25:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,740
Website GitHub

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.

Txp Builders – finely-crafted code, design and Txp

Offline

#266 2022-03-18 08:54:27

gilibaus
Member
From: Italy
Registered: 2013-08-14
Posts: 91
Website

Re: smd_xml : extract data from XML feeds

Bloke wrote #332946:

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.

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,740
Website GitHub

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.

Txp Builders – finely-crafted code, design and Txp

Offline

#268 2022-03-18 12:09:27

gilibaus
Member
From: Italy
Registered: 2013-08-14
Posts: 91
Website

Re: smd_xml : extract data from XML feeds

Great thanks! It finally works.

Offline

Board footer

Powered by FluxBB