Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
The tag within... a tag
I seriously tried to find a similar question in this forum! Honest!
I want to display some thumbnails in an article using the <code><txp:thumbnail /></code> tag. They won’t be placed inline with the text but in a div… and this is where things got out of control…
A user/editor of this site would use some custom fields to input the value of the picture’s id needed by this form:
<code><txp:thumbnail id=”<txp:custom_field name=“Image_1” />” poplink=“1” /></code>
If a user would input the value “12” in the custom_field named “Image_1”, txp would return this value:
<code><txp:thumbnail id=“12” poplink=“1” /></code>
Unhappily, this form abruptly ends as it finds the first closing characters ( />) and as a result I only get:
<code>/>” poplink=“1” /></code>
Is there any way to workaround mine messy code?
Last edited by patchwork (2006-01-29 22:36:32)
Offline
#2 2006-01-29 22:47:01
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: The tag within... a tag
You can’t use tags within tag attributes. The FAQ explains this, and suggests an approach that will work.
Alex
Offline
Re: The tag within... a tag
You are quite right, sorry!
Thanks.
Last edited by patchwork (2006-01-30 09:25:29)
Offline
Re: The tag within... a tag
Please, correct-me if I’m wrong…
By now I learned that Textpattern transforms txp tags into regular php functions witch are understood by the server. This will allow me to insert a php function directly on my form instead of using the equivalent txp tag. e.g.: <code><txptag phpform /></code>.
My question is, where can I find the php equivalent to the txp <code><txp:custom_field /></code> tag? Is there any documentation? Or can I somehow read the result delivered by Textpattern to the php server…
Last edited by patchwork (2006-01-30 17:04:21)
Offline
#5 2006-01-30 15:58:47
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: The tag within... a tag
You can find function custom_field in /publish/taghandlers.php.
Offline
Re: The tag within... a tag
I recently needed something like this, and this is how I pulled it off:
I downloaded rei_show_custom plugin, and installed it.
Then I hacked the code around to show this:
<del><code>function customfieldbyid($atts){
global $thisarticle;
$id=$thisarticle[“thisid”];
$custom_field=“custom_”.$atts;
$res=safe_rows($custom_field,“textpattern”,“id=’$id’”);
$out=$res [0][$custom_field];
return $out;
}</code></del>
This is where how you would implement it: <code><txp:php> echo (‘<txp:thumbnail id=”’.customfieldbyid(5).’” poplink=“1” />’); </txp:php></code>. Do note that there isn’t supposed to be a space between <code>$res</code> and <code>0</code> on the sixth line.
<del>‘5’ is the id of the custom field where the user would enter the ID of the image. You could make this more robust if you enclosed the whole thing inside of a <code><txp:if_custom_field name=“Image_1”></txp:if_custom_field></code></del>
While this isn’t the most elegant solution out there, it should work fine. :)
See post #8 for that more elegant solution
Last edited by mr.riff (2006-01-30 21:27:02)
I’ve PIZZA.
Offline
Re: The tag within... a tag
Ok, so this is the php code behind the <code><txp:custom_field /></code> tag
<code><?php
function custom_field($atts)
{
global $thisarticle, $prefs;
extract(lAtts(array(
‘name’ => @$prefs[‘custom_1_set’],
),$atts));
if (isset($thisarticle[$name]))
return $thisarticle[$name];
}
?></code>
What will I put inside the <code><txp:php></txp:php></code> tags?
The example in the FAQs isn’t the easiest to follow to someone not familiar with php (such as me).
I can’t find my Roseta Stone – that is, I can’t find the <code><txp:s /></code> tag inside the taghandlers.php document that would help me understand the process.
Mr.riff, Isn’t the rei_show_custom plugin very similar to the inbuilt <code><txp:custom_field /></code> tag? edit== btw, I loved your site, and I have a cat that’s very similar to the one in your gallery (http://itsxjustxanotherxday.com/flickr/64170387/) ;o) !==
Thank you all for your support!!
Last edited by patchwork (2006-01-30 18:07:11)
Offline
Re: The tag within... a tag
We’ve so many cats, its not funny! you could just call me riff, though. :)
I liked the rei_show_custom plugin better because it was easier to understand :) but I’ve taken another stab at texpattern’s code (of what you posted) and I think I’ve a fair solution:
<code><txp:php>
global $thisarticle, $prefs;
$name = @$prefs[‘custom_1_set’];
echo(‘<txp:thumbnail id=”’.$thisarticle[$name].’” poplink=“1” />’);
</txp:php></code>
All you have to do now, is change the number in “custom_1_set” to whatever is the number of the custom field you’d like to use.
Please do excuse the mess of code that I suggested in my earlier post – in retrospect it looks like a pile of elephant poo. I’ve also got to update the code for my website as well, I’d never have thought of this if you hadn’t asked – Thanks a bunch! :)
Last edited by mr.riff (2006-01-30 21:28:48)
I’ve PIZZA.
Offline
Re: The tag within... a tag
Thanks a bunch? Those should be my words!!
Thanks a bunch… a lot!! ;o)
edit==
I spent most of my weekend triyng to solve this problem.
as for my cat, I’ve placed a picture of him in my website, so you could see what I mean by “identical”.
==edit
Last edited by patchwork (2006-01-30 23:02:09)
Offline
Pages: 1