Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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
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
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
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
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
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
Re: Getting a txp:variable that's been set in article body... possible?
philwareham wrote #324193:
If there is a cleaner way, please let me know, otherwise I’m happy this is working.
How about:
<txp:hide process><txp:body /></txp:hide>
Almost the same: no output but processed contents but also no variable needed.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Getting a txp:variable that's been set in article body... possible?
jakob wrote #324194:
How about …
Didn’t work for my particular use case. Hiding the body seems to hide the variable too.
Offline