Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-02-28 12:18:08

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

php help request

I have two cases where I need to put tags inside tags, which breaks the Txp parser.

mr wet kindly pointed me to this post from Sencer which explains how the quick and ugly solution is to write the middle tag in php

alas I am a buffoon, and can’t work out how th write the php myself, so I was hoping someone might take pity and do it for me ;)

first one
<code><txp:file_download_list sort=“description” category=”<txp:custom_field name=“cat-number” /> /></code>

second one
<code><txp:if_custom_field name=‘purchase-URL’>available from <a href=”<txp:custom_field name=‘purchase-URL’>” > <txp:custom_field name=‘purchase-URL’ /></a></txp:if_custom_field></code>

Offline

#2 2006-02-28 13:26:58

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: php help request

I will provide some hints on the solution to this puzzling exercise:

Numero uno:

<txp:php>
$c = custom_field( array("name"=>"cat-number") );
$a = array("sort" => "description", "category"=> $c);
echo file_download_list ( $a );
</txp:php>

Numero due:

<txp:php>
$u = custom_field( array("name"=>"purchase-URL") );
echo "<a href=\"$u\">";
</txp:php>
<txp:custom_field name="purchase-URL" /></a>

Caveat: This will work in forms and pages, not in articles as Textile chooses to rewrite brackets even in php blocks. If you need that seqences inside a single article, you will have to put them in a form beforehand and output that form from the article with <txp:output_form />.

Offline

#3 2006-02-28 13:53:07

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: php help request

can I squeeze one more hint out of you? I am still puzzled…

for numero uno:

how should I insert your php into my code?
<code><txp:file_download_list sort=“description” category=”<txp:custom_field name=“cat-number” /> /></code>
does it relace it all?
or the attributes?
or just the category=”“ attribute?

Offline

#4 2006-02-28 13:59:16

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: php help request

It is intended to replace the whole shebang.

Line 2 is replacing txp:category="&lt;txp:custom_field name="cat-number"&gt;"
Line 3 is replacing sort="description" category=" ... result from Line 2... "
Line 4 writes the whole HTML sequence by using the products of the preceeding lines and feeding them to file_download_list.

Offline

#5 2006-02-28 14:17:34

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: php help request

thanks wet
numero due works a treat, but numero uno outputs nothing… bah

Offline

#6 2006-02-28 17:09:20

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: php help request

Try this:

<txp:php>
$c = custom_field( array("name"=>"cat-number") );
echo "c: $c";
$a = array("sort" => "description", "category"=> $c);
echo "a: $a";
echo file_download_list ( $a );
</txp:php>

Does this write anything?

Offline

#7 2006-02-28 17:14:10

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: php help request

yep it says
<code>c: Sarah001a: Array</code>
Sarah001 correctly being the value in the custom field

Offline

#8 2006-02-28 17:34:32

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: php help request

Strange. I’m basically out of hints, this works as expected on my test site.

One last cross check: Do you get results by adding a static tag like that: <txp:file_download_list sort="description" category="Sarah001" />?

Offline

#9 2006-02-28 17:45:14

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: php help request

unfortunately for both of us, I was a bit too accurate when I called myself a buffoon
your first bit of code was perfect… I hadn’t checked to make sure the value in the custom field actually matched a valid file-category name! duh.
and if I can’t even get it right, not sure how my client is gonna!
might hafta rethink

thanks very much for lending your brains

Offline

Board footer

Powered by FluxBB