Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-08-25 08:28:33

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,513
Website

Inserting some block of text in a feed after article body

Looking for some way to (always) insert a block of text after <txp:body /> in a feed. Think about it as a block in the (individual) article template that is only visible to those users receiving the feed. Or maybe a form that is appended to <txp:body /> when the request is a feed.

Basically it would be some way to wrap that block in a <txp:if_feed />; of course that tag does not exist :-/.


Where is that emoji for a solar powered submarine when you need it ?

Offline

#2 2021-08-25 09:51:23

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

Re: Inserting some block of text in a feed after article body

Hmmmm. Not easy, as far as I can see. Short of inserting some evaluate tag code in every Body field, I’m not sure feeds are wired up that way.

It’d be great if we could defer feed content to a named form (albeit you run the risk of breaking the feed output) so you could customise the output somehow, though I appreciate that’s fraught with corner cases.

We do have a callback, although in its current form it can only add nodes to the feed and not content to a named field. Example:

register_callback('abc_feed_append', 'rss_entry');
register_callback('abc_feed_append', 'atom_entry');

function abc_feed_append($evt, $stp)
{
    $out = parse(<<<EOTXP
<txp:evaluate query='starts-with( "<txp:page_url/>", "/rss")'>
Hello RSS world!
</txp:evaluate>
<txp:evaluate query='starts-with( "<txp:page_url/>", "/atom")'>
Hello Atom world!
</txp:evaluate>
EOTXP
    );

    return $out;
}

That simply appends the content, which of course will break the feed because it needs to be output in the correct format. There’s an <enclosure> element which might be possible to hijack but that seems to be for attachments.

So, ummm, not sure. If there was a way to intercept the body tag via a callback, that’d be useful in this context but I think the longer-term solution for this is to find a way to customise the feed layout by shoving everything through a form and letting you go nuts. That would also open up the avenue for custom and future feed formats that we might not support immediately.

Adding a form attribute (and container support?) to our feed link generation tag might be able to register a callback that would direct the link through the form/container when it comes time to render it on click. That’d be pretty neat and allow you to do whatever the heck you like, but maybe that’s too much control?


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

#3 2021-08-25 10:20:59

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,513
Website

Re: Inserting some block of text in a feed after article body

Thanks for the feedback. Yes, I suspected it could be rather difficult and probably quite messy.
The one option I thought possible is inserting the block of text directly inside the body of the article (a ready-to-use short form) but the author need to remember to insert it manually. Only workable for a single author site.

Longer term, yeah, the ability to customise feeds would be great… feeds are a technology that is very sensitive to errors (XML).


Where is that emoji for a solar powered submarine when you need it ?

Offline

#4 2021-08-25 11:30:18

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

Re: Inserting some block of text in a feed after article body

Well you could insert a short code for sure. Steal the evaluate conditional(s) out of the plugin above and put them in a form. Then just add the call to that form in your body text. The block will only be output if the body is viewed inside a feed.


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

#5 2021-08-25 16:38:21

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,691
GitHub

Re: Inserting some block of text in a feed after article body

phiw13 wrote #331462:

Longer term, yeah, the ability to customise feeds would be great… feeds are a technology that is very sensitive to errors (XML).

There’s also this that could be considered.

Offline

#6 2021-08-25 18:51:28

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

Re: Inserting some block of text in a feed after article body

Good link reminder, Pete.

What Oleg suggested is precisely what I implied above. It’d be really handy to be able to essentially map a URL (full or partial) to a form so it can be used to do something outside of the regular Section->Page+CSS.

That way, any specific format you wanted – perhaps to syndicate content or even just provide an article in an alternative machine readable format – would be up to the site administrator. Opens up a tonne of possibilities.


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

#7 2021-08-25 18:53:40

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,691
GitHub

Re: Inserting some block of text in a feed after article body

Bloke wrote #331465:

What Oleg suggested is precisely what I implied above.

Oh yeah! Whoops.

Offline

#8 2021-08-25 19:11:44

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

Re: Inserting some block of text in a feed after article body

Wasn’t being snarky, sorry if it came across that way. I was just surprised at the overlap and forgot Oleg had already floated the idea.


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

#9 2021-08-25 21:30:18

etc
Developer
Registered: 2010-11-11
Posts: 4,548
Website GitHub

Re: Inserting some block of text in a feed after article body

Bloke wrote #331461:

If there was a way to intercept the body tag via a callback, that’d be useful in this context

At least in 4.8.8, global $thisarticle is already populated when callback fires. So your plugin could do just this:

global $thisarticle;
$thisarticle['body'] .= '<p>The text to append</p>';

Offline

#10 2021-08-26 03:11:54

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,513
Website

Re: Inserting some block of text in a feed after article body

Bloke wrote #331463:

Well you could insert a short code for sure. Steal the evaluate conditional(s) out of the plugin above and put them in a form.

Yeah, that was my idea when I saw your <evaluate /> conditional(s). A shortcode using those 2 conditionals with the body of the message, and then inserting the shortcode at the bottom of the article(s). I have now tested it out locally and it works great, including with HTML or Textile formatting. Both Vienna and NetNewsWire “see” and render the message.

The one issue is that the author has to remember to insert that shortcode.

BTW on could probably use that concept to insert a message to feed readers for one article only, by using the shortcode as a container tag.

Thanks to all.


Where is that emoji for a solar powered submarine when you need it ?

Offline

#11 2021-08-26 06:54:21

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,691
GitHub

Re: Inserting some block of text in a feed after article body

Bloke wrote #331467:

Wasn’t being snarky, sorry if it came across that way.

Not even slightly. I should’ve read more carefully.

Offline

Board footer

Powered by FluxBB