Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
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
Re: php help request
It is intended to replace the whole shebang.
Line 2 is replacing txp:category="<txp:custom_field name="cat-number">"
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
Re: php help request
thanks wet
numero due works a treat, but numero uno outputs nothing… bah
Offline
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
Re: php help request
yep it says
<code>c: Sarah001a: Array</code>
Sarah001 correctly being the value in the custom field
Offline
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
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
Pages: 1