Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-08-22 17:56:45
- aboyce
- New Member
- Registered: 2005-12-09
- Posts: 3
txp:tags within tags
Hello All,
I’m trying the following
<code>
<txp:if_custom_field name=“email”>
<txp:email email=”<txp:custom_field name=“email” />” />
</txp:if_custom_field>
</code>
which outputs:
<code>
“” />
</code>
Is there another way to embed the custom field into the email tag?
best,
alan
Last edited by aboyce (2006-08-22 17:57:35)
Offline
#2 2006-08-22 18:22:18
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: txp:tags within tags
<txp:if_custom_field name="email"><txp:php>
echo email(array(
'email' => custom_field(array('name' => 'email'))
));
</txp:php></txp:if_custom_field>
Offline
#3 2006-08-22 19:15:58
- aboyce
- New Member
- Registered: 2005-12-09
- Posts: 3
Re: txp:tags within tags
Mary, Thanks! I missed the faq completely.
Alan
Offline
#4 2006-08-22 23:00:48
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: txp:tags within tags
Transferred to my (faulty) code
<code> <txp:ras_if_days_not_passed offset=”<txp:custom_field name=“vanishes in__days” />”> </code>
this would read
<code><txp:php></code>
<code>echo ras_if_days_not_passed(array(‘offset’ => custom_field(array(‘name’ => ‘vanishes in__days’))));</code>
<code></txp:php></code>
which at least doesn’t produce errors reading like «Parse error: syntax error, unexpected T_STRING, expecting ‘)’ in [ … ]».
Does this mean I have transferred it correctly? (I’m asking because the article in question doesn’t vanish as desired and there may be a variety of reasons for it.)
Another point:
txp:ras_if_days_not_passed is a container tag. So I left the … let me call it “closing bracket” <code> </txp:ras_if_days_not_passed></code> under my code. Is this correct? [If so (as I’m presuming yet) then it could be mentioned in the FAQ’s page linked above how to handle container tags when putting tags within tags.]
And a third one:
Can I find a pattern/scheme anywhere that would help me/an absolute PHP-layman transferring commands with even more parameters to < txp:php >-code like for instance in <code><txp:article_custom form=“month_list” month=” [ custom fieldname-n here ] “ sortby=“Section” sortdir=“asc” /></code>? This might release some of the attention of all you cracks and helpers.
Last edited by uli (2006-08-22 23:29:02)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#5 2006-08-23 01:05:32
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: txp:tags within tags
Plugin Author Resources includes a link to tutorials by Alex, which show you the basics of how Textpattern tags (whether plugin or built-in) work. The info you’re missing is details about $thing.
<txp:php>
$atts = array(
'offset' => custom_field(array('name' => 'vanishes in__days'))
);
$thing = 'whatever you would normally wrap the tag around';
echo ras_if_days_not_passed($atts, $thing);
</txp:php>
It is not mentioned in the FAQ because we don’t really want to encourage using PHP instead of built-in tags, especially if you haven’t a clue how it works. It works when you’re in a bind, but it is not a habit you should be forming.
Offline
#6 2006-08-23 02:13:35
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: txp:tags within tags
Glad you answered, Mary! I read the forum for several hours and saw how often questions about tags inside of tags arise (and how often you are involved in answering). So I can appreciate your reply even more!
Though the «$atts = array-$thing»-thing leaves me with my brows high above the parting (“Which fishbone of my code is left yet to put in the middle of it?”) it sounds like a cooking recipe I should keep. I’m a bit too tired now to get it or even to apply it , it’s 4 am here. :)) ButI think I’m beginning to really like txp, I like this kind of wrapping snippets into forms into templates and this struggling and wrestling with code snippets.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#7 2006-08-24 14:51:28
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: txp:tags within tags
Mary, this so gorgeous! I never expected this could be so easy to get to work! I thought I had to convert my txp-code into php following a certain scheme. But as I had no plan of how to do it I started with the easiest possible way, just pasting in my code and … tataradumm! … it works! Fantastic! This makes using the txp backend child’s play for my client. I thank you soo much! Like I felt: this is a cooking recipe I’ll keep well! :))
A last little point: If one forgets to fill in the custom field “vanishes in … days” the article never is published. Written in Javascript I’d easily do something like <code>if (document.txp_form.vanishes_in__days.value == “”) {var vanishes_in…days = 9999}</code>. How’d this be applied to your component in php?
If I make use of your proposal (compared to calling ras-if-days-not-passed directly) I have to increase by one the value to enter into “vanishes in … days”. Is this something you’d expect?
Once again: I’m really grateful for this code component and your help! This is my first attempt to apply any CMS to a job, and it works perfectly, and will perfectly well for my client! I’m incredibly relieved! :)
Last edited by uli (2006-08-24 14:59:37)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#8 2006-08-25 04:38:32
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: txp:tags within tags
A last little point: If one forgets to fill in the custom field “vanishes in … days” the article never is published. Written in Javascript I’d easily do something like… How’d this be applied to your component in php?
<txp:php>
$vanishes = custom_field(array('name' => 'vanishes in__days'));
if (!$vanishes)
{
$vanishes = 9999;
}
$thing = 'whatever you would normally wrap the tag around';
echo ras_if_days_not_passed(array('offset' => $vanishes), $thing);
</txp:php>
If I make use of your proposal (compared to calling ras-if-days-not-passed directly) I have to increase by one the value to enter into “vanishes in … days”. Is this something you’d expect?
I’m not familiar with this plugin at all, so I couldn’t say what the expected behaviour is. Another user or the plugin developer will likely be able to help you out there.
Offline
#9 2006-08-25 15:40:12
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: txp:tags within tags
hi mary,
it works like hell!
thank you!

author’s knee, taken today
especially for this occasion
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: txp:tags within tags
Hi Mary,
I’m just trying out your email embedding code. I have a contact name (<code><txp:title /></code>) and want to embed a custom field email address (<code><txp:if_custom_field name=“contact_email”></code>) so that when the name is outputted it becomes their email link. If there’s no email, it just outputs the name.
My code is
<code>
<txp:if_custom_field name=“contact_email”>
<txp:php>echo email(array(‘contact_email’ => custom_field(array(‘contact_name’ => ‘contact_email’))));</txp:php>
<txp:else /><txp:title /></txp:if_custom_field>
</code>
But I’m getting a tag error <code><txp:notice/> -> Textpattern warning: unknown Tag</code> and names with email addresses as displaying as “
Can you offer any advice on where I’m going wrong?
Many thanks
Mark.
Offline
Re: txp:tags within tags
can you use php to get around this “tag as an attribute” problem i am trying to achieve?
<code><txp:article_custom form=“aboutTheAuthor” section=“About-The-Author” author=”<txp:author/>”/></code>
Offline
Re: txp:tags within tags
decoderltd: <code><txp:if_custom_field name=“contact_email”>
<txp:php>echo email(array(‘email’ => custom_field(array(‘name’ => ‘contact_email’)), ‘title’ => title(array()) ));</txp:php>
<txp:else /><txp:title /></txp:if_custom_field></code>
alittle116: <code><txp:php>echo article_custom(array(‘form’ => ‘aboutTheAuthor’, ‘section’ => ‘About-The-Author’, ‘author’ => author(array()) ) );</txp:php></code>
Last edited by ruud (2006-09-08 15:04:13)
Offline