Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-01 16:14:00

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,337
Website

Getting a txp:variable that's been set in article body... possible?

Hi all,

I thought this would be possible, but not sure it can…

I want to check if a <txp:variable /> tag has been defined in the article body field, and then act upon it. However I can’t seem to get it working. Any ideas?

Offline

#2 2020-07-01 16:50:02

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,313
Website

Re: Getting a txp:variable that's been set in article body... possible?

I just tried an experiment: I put

<txp:variable name="secretvariable" value="something" />

in my article default form and

<txp:variable name="secretvariable" />

in my footer form and it worked.

Are you calculating the value? You could have it display in the article form just to make sure it is getting set properly.

Offline

#3 2020-07-01 16:52:11

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,337
Website

Re: Getting a txp:variable that's been set in article body... possible?

Sorry I mean a variable tag written in the body text area of an article.

Offline

#4 2020-07-01 17:24:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: Getting a txp:variable that's been set in article body... possible?

It works, just watch out for Textile mangling it. So either Leave Text Untouched, or escape the variable with == or notextile. or something.


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 2020-07-01 18:27:41

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 187
Website

Re: Getting a txp:variable that's been set in article body... possible?

Its something we use extensively in the artedomus site; so far no Textile mangling :)

I often require a variable from the body field early on in an article form, and wrap the <txp:body /> in another variable eg. <txp:variable name="body"><txp:body /></txp:variable>.

This allows me to extract said variable from the body field without displaying the remainder of the body field.

Offline

#6 2020-07-01 19:03:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: Getting a txp:variable that's been set in article body... possible?

giz wrote #324160:

This allows me to extract said variable from the body field without displaying the remainder of the body field.

You might be able to do the same trick but save yourself making a variable to hold the body content. You can access it directly like this from your form:

<txp:custom_field name="body" />

Sshhhhh…


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 2020-07-01 19:54:25

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 187
Website

Re: Getting a txp:variable that's been set in article body... possible?

Bloke wrote #324162:

You might be able to do the same trick but save yourself making a variable to hold the body content. You can access it directly like this from your form:

<txp:custom_field name="body" />...

Sshhhhh…

Old habits die hard! :)

Offline

#8 2020-07-01 20:34:55

etc
Developer
Registered: 2010-11-11
Posts: 3,768
Website

Re: Getting a txp:variable that's been set in article body... possible?

Also make sure that <txp:body /> is called before you act upon its <txp:variable />.

Offline

#9 2020-07-02 07:21:04

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,337
Website

Re: Getting a txp:variable that's been set in article body... possible?

etc wrote #324167:

Also make sure that <txp:body /> is called before you act upon its <txp:variable />.

I think this is the problem, thanks. Will test later. I only need to read the body in this case, not actually display its contents.

Offline

#10 2020-07-02 11:48:30

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,337
Website

Re: Getting a txp:variable that's been set in article body... possible?

Thanks all, I solved this by using giz’s solution…

<txp:variable name="body"><txp:body /></txp:variable>

…to call the body content before I use the <txp:if_variable> check, which was where the original problem arose. FYI I tried Stef’s <txp:custom_field name="body" /> suggestion but that output actual contents of body, which I didn’t want to do (only read the contents).

If there is a cleaner way, please let me know, otherwise I’m happy this is working.

Offline

Board footer

Powered by FluxBB