Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-07-10 23:40:35
- jhyde
- New Member
- Registered: 2006-07-10
- Posts: 5
Problems using a custom field within another txp tag
I can’t seem to get the following article form to work.
<code>
<ul>
<li>
<txp:file_download_link id=”<txp:custom_field name=“file_download_id” />” >
<txp:file_download_description /> [<txp:file_download_size format=“auto” decimals=“2” />]
</txp:file_download_link>
</li>
</ul>
</code>
The html output looks something like:
<code>
<ul><li><a href=“http://localhost/txp/index.php?s=file_download&id=”></a>” > []</txp:file_download_link></li></ul>
</code>
removing the custom field tag and entering an integer works just fine of course. Displaying the custom field outside of the txp tag works just fine. BTW the value for the custom field is an integer (I was working with 3, 4, and 5).
Any help or insight would be greatly appreciated.
Offline
Re: Problems using a custom field within another txp tag
hi jhyde,
check the FAQs
There is one named “Can I use tags inside tags?” that explain that yu can’t use TxP tags inside TxP tags.
Offline
#3 2006-07-11 00:12:09
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Problems using a custom field within another txp tag
In addition, custom fields are only for articles, so they only work from article forms at present.
Offline
#4 2006-07-11 00:26:51
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: Problems using a custom field within another txp tag
It would be nice if you could though :)
Offline
#5 2006-07-11 00:45:33
- jhyde
- New Member
- Registered: 2006-07-10
- Posts: 5
Re: Problems using a custom field within another txp tag
I’ve read the FAQ, and I am now trying to call the tag handler function directly to populate the attribute value. Here is the code:
<code>
<ul><li>
<txp:php>
echo file_download_link(
array(‘id’=>$GLOBALS[‘pretext’][‘custom_4’])
);
</txp:php>
<txp:file_download_description /> [<txp:file_download_size format=“auto” decimals=“2” />]</txp:file_download_link>
</li></ul>
</code>
So far, this does NOT work.
This is definitely in a article form. I’m PHP illiterate so… I did look into the database and the field I want to display as the attribute is labelled custom_4.
Thx
Offline
#6 2006-07-11 01:28:52
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Problems using a custom field within another txp tag
Do $GLOBALS['thisarticle']['custom_4']
Offline
#7 2006-07-11 10:40:56
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: Problems using a custom field within another txp tag
Wow…I had no idea you could do this with PHP. I need to read that FAQ more often!
In my case, I am trying to get the contents of “custom_4” to spill into the following attribute dynamically:
<code><txp:chh_article_custom wraptag=“li” category=“Books,Reviews” custom_4=”<txp:custom_field name=“custom_4” />” /></code>
My first attempt at PHP has proved very humbling:
<code><txp:php>
echo chh_article_custom
(array(‘custfield’=>$GLOBALS[‘thisarticle’][‘custom_4’]) );
(array(‘category’=>$GLOBALS[‘thisarticle’][‘Books,Reviews’]) );
(array(‘wraptag’=>$GLOBALS[‘thisarticle’][‘li’]) ); </txp:php></code>
The above is sitting inside an article form which I am calling up from inside an article. How can I make it work?
Last edited by Ace of Dubs (2006-07-11 12:08:36)
Offline
#8 2006-07-11 17:22:52
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Problems using a custom field within another txp tag
<txp:php>
global $thisarticle;
if (!empty($thisarticle['custom_4']))
{
echo chh_article_custom(array(
'category' => 'Books,Reviews',
'custfield' => $thisarticle['custom_4'],
'wraptag' => 'li'
));
}
</txp:php>
:)
Last edited by Mary (2006-07-11 18:15:32)
Offline
#9 2006-07-11 17:44:57
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: Problems using a custom field within another txp tag
Hey, that’s encouraging how close I was! :D
Your version is prettier though, sad to say it doesn’t work yet
Details:
Right now I am outputting this PHP in a misc form from inside an article.
Everything parses just fine, except that I get a list of articles that have custom_4 filled out, regardless of the content.
My aim is only to call up those articles whose values for custom_4 are identical to the current article. Is this possible?
Edit: I deleted one of the categories to see if the other arrays were working..apparently, the custom fields are not working at all and no links show up.
Last edited by Ace of Dubs (2006-07-11 18:13:31)
Offline
#10 2006-07-11 18:16:19
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Problems using a custom field within another txp tag
I updated the code above. Remember to change custfield to the name/title of your custom_4 field.
Offline
#11 2006-07-11 18:36:09
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: Problems using a custom field within another txp tag
Just tried it and now I get zero output, so then I tried putting my custom_4 title in the (!empty($thisarticle[‘custom_4’])) and I got the same unfiltered list I got before. PHP sure is funky..
Last edited by Ace of Dubs (2006-07-11 18:36:38)
Offline
#12 2006-07-11 19:48:04
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Problems using a custom field within another txp tag
If you’re getting zero output, then chances are that your article either doesn’t have a value in your custom_4 field, or you might’ve misspelled your custom field’s name. What is your custom field’s name?
Offline
#13 2006-07-11 20:27:07
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: Problems using a custom field within another txp tag
My apologies…for the sake of not confusing anyone, I was rolling with jhyde’s example. In reality I am using custom_3, which is named HCM. That’s the catalog prefix for all releases. It gets plugged in with a 3-digit number whenever there is a new record or a licensing/review of said record. This way all articles about the release gets shown under “Related News”
You can see a working example here:
Link
I have achieved the desired effect, but it requires the user to modify the release number on a per article basis in the following code:
<code><txp:chh_article_custom category=“Compilations,Reviews” HCM=”###” /></code>
My problem page is located here:
Link
Even though I already have an article with the HCM field set to “006”, it still doesn’t show up
Here is the PHP I am using in the (misc) form:
<code> <txp:php>
global $thisarticle;
if (!empty($thisarticle[‘custom_3’]))
{
echo chh_article_custom(array(
‘category’ => ‘Compilations,Reviews’,
‘HCM’ => $thisarticle[‘custom_3’],
‘wraptag’ => ‘li’
));
}
</txp:php></code>
If there is no fix then I suppose it’s no big deal and my clients can work with what I’ve hacked together. Still not giving up hope for a more elegant solution tho..
Offline
#14 2006-07-11 20:29:09
- jhyde
- New Member
- Registered: 2006-07-10
- Posts: 5
Re: Problems using a custom field within another txp tag
Mary,
Thanks to you I am very close to a solution. I am getting an error
tag_error <txp:php> -> Warning: Missing argument 2 for file_download_link() on line 1931
I’m guessing this is because I am using a container tag (file_download_link). Since I am calling the tag handler directly, I’m guessing I need something in there to tell it it’s a container tag.
Here is the code:
<code>
<ul><li>
<txp:php>
global $thisarticle;
The source that it outputs:
<code>
<ul><li>
<a href=“http://localhost/txp/index.php?s=file_download&id=6”></a>
Warren Miller show reel (.zip) [5.22mb]</txp:file_download_link>
</li></ul>
</code>
The ending “a”(<code></a></code>) tag should be where the <code></txp:file_download_link></code> is.
Thanks again for all your help.
Offline
#15 2006-07-12 02:04:17
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Problems using a custom field within another txp tag
For the second one:
<ul><li>
<txp:php>
global $thisfile;
$atts = array('id' => $thisfile['id']);
$thing = '<txp:file_download_description /> [<txp:file_download_size format="auto" decimals="2" />]';
echo file_download_link($atts, $thing);
</txp:php>
</li></ul>
For the first one, as far as I can tell, that should work, but I don’t know the inner workings of that plugin to have certainty. I’ve gotta go out for the moment, but if I come back and you’ve not gotten any further, then I’ll install the plugin myself and figure it out. :)
Offline