Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-09-23 10:47:41

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 184
Website

Cannot get escaping "tidy, textile" working

<txp:body escape="tidy, textile"/>

Should give me the content of the body field without the surrounding <p>, correct?
In my case it seems not to work at all and I still get surrounding <p> and I am wondering why.

This works fine though:

<txp:body escape="tidy, p"/>

Offline

#2 2021-09-23 11:40:35

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

Re: Cannot get escaping "tidy, textile" working

demoncleaner wrote #331650:

<txp:body escape="tidy, textile"/>...

Should give me the content of the body field without the surrounding <p>, correct?

No, it should textile the output of <txp:body /> (without wrapping it with <p>) after some whitespace normalization (tidy). But <txp:body /> output is already textiled, so escape has no effect here.

Offline

#3 2021-09-23 12:59:22

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 184
Website

Re: Cannot get escaping "tidy, textile" working

OK. Thanks, I almost understand.

But shouldn´t

<txp:variable name="test" value='<txp:body/>' escape="tidy, textile" output/>

work than?

But that gives me still surounding <p>.
What am I missing?

Or let me ask in a different way:
What would I have to do when I want the contents of the body field output without any surounding <p>.
(Changing the format in the backend cannot be an option unfortunately.)

Last edited by demoncleaner (2021-09-23 13:01:44)

Offline

#4 2021-09-23 14:07:37

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

Re: Cannot get escaping "tidy, textile" working

The Body field (and Excerpt) already has Textile applied, and already has the surrounding ‘p’ tags.

Telling escape to tidy it (remove newlines and add a preceding space) and then pass it through Textile is a waste of time, since it’s already been passed through Textile. The <txp:body> tag actually outputs the Body_html field (at least, if it doesn’t, it should!). It applies Textile on save, not on output, for performance reasons. Additionally, you might get odd results if it encounters something in the HTML that it doesn’t quite understand.

In your <txp:variable> example, the same applies. You’re populating the variable with HTML from the article body, and then asking the variable to pass its content through Textile. That’ll have no effect.


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-09-23 14:12:46

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

Re: Cannot get escaping "tidy, textile" working

demoncleaner wrote #331655:

What would I have to do when I want the contents of the body field output without any surounding <p>.

<txp:custom_field name="body" escape="tidy, textile" />

:)

(though that’ll have a performance impact on your pages as it re-Textile’s the entire article on the fly)

Last edited by Bloke (2021-09-23 14:13:38)


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

#6 2021-09-23 15:10:34

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 184
Website

Re: Cannot get escaping "tidy, textile" working

OK. I see =). Thank you.
Maybe then that´s a bit misleading here for somebody that has no clue how exactly it works in the background.

https://docs.textpattern.com/tags/learning/#available-escape-values

Remove spaces/newlines, prepend a single space to remove the surrounding <p> tag, then Textile the content.

I thought I can use it in a situation where I just use the body field for just one sentence or so and do not want it to be wrapped in <p>. Get rid of it and textile it again.

Of course changing the format in the backend is an option as well. But I normally try to avoid it because this can easily be overseen by somebody who is not so much into textpattern.

At least I know now why it is not working. Think I change my idea of how to use the body field in those cases and better make use of a custom_field. Thanks again!

Last edited by demoncleaner (2021-09-23 15:10:53)

Offline

#7 2021-09-24 11:34:59

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

Re: Cannot get escaping "tidy, textile" working

demoncleaner wrote #331658:

Maybe then that´s a bit misleading here for somebody that has no clue how exactly it works in the background.

The docs are a bit long, but they do state that

global attributes cannot intervene in a tag’s internal processing and are applied only to the tag’s output.

So, when the global escape="textile" is applied to <txp:body />, it is too late, it will just be textiled a second time.

Offline

#8 2021-09-25 04:47:52

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 184
Website

Re: Cannot get escaping "tidy, textile" working

OK. Got it. So as far as I can see then in my scenario escape="tidy, p" or better just using a custom_field instead of body would be the weapon of choice. Thanks guys.

Offline

Board footer

Powered by FluxBB