Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Nested if tags to employ a custom field as selector attribute
lspace/rspace is fine by me. Seems like a reasonable addition.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Nested if tags to employ a custom field as selector attribute
But then [l|r]comma
seems useful too… bloatware in action :-)
Offline
Re: Nested if tags to employ a custom field as selector attribute
etc wrote #309580:
But then
[l|r]comma
seems useful too… bloatware in action :-)
Ah, true. Without params, this does seem just the analog of trim. I mean, in PHP, trim
(by default) trims space-looking characters, but you can supply your own set of chars to override it. r/l
[something] would be an ideal candidate for this treatment if only we had a way of passing arguments…
I don’t mind. Introduce it if you like and it has broad applicability. But if there are any reservations about it for future, then let’s conserve our energy and make it better in the next version with params (or something).
As Robert DeNiro says in Ronin: “If there’s doubt, there is no doubt.”
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Nested if tags to employ a custom field as selector attribute
And a pipe separator for denoting the item to trim or add, e.g. escape="rtrim|,"
or "radd| "
or "ladd|space
?
BTW, can you chain escape
parameters?
TXP Builders – finely-crafted code, design and txp
Offline
Offline
Re: Nested if tags to employ a custom field as selector attribute
Wow, not getting notifications for all these replies and missed them. Sorry guys. Didn’t mean to ignore you.
jakob wrote #309563:
<figure class="hero <txp:custom_field name="Hero_width" />">...
… The only ‘wastage’ is a space when you don’t use it.
Good call. I could live with the little wastage.
What’s also a possibility if you want a range of different article layouts is to set up different article form layouts and then use the override form dropdown in the write tab to switch to a special layout for a specific article when you need it.
I’d rather avoid all the extra forms in this case, but thank you for the clear example of using an override form, which I have never done before. That’s a clear demonstration of the value.
Offline
Re: Nested if tags to employ a custom field as selector attribute
etc wrote #309564:
We could add some
[r|l]space
values to the globalescape
attribute, so<figure class="hero<txp:custom_field name="Hero_width" escape="lspace" />">...
Nice! So that will be functional after 4.7 stable, I take it?
Offline
Re: Nested if tags to employ a custom field as selector attribute
This is the same bit of code as originally talked about in this thread, added in an article form:
<txp:if_article_image>
<figure class="hero<txp:if_custom_field name="Hero_width"> <txp:custom_field name="Hero_width" /></txp:if_custom_field>"><txp:article_image height="0" width="0" />
<txp:image_info id='<txp:article_id />' type="caption" wraptag="figcaption" /></figure>
<txp:else />
<txp:hide>There is no article image</txp:hide>
</txp:if_article_image>
But the issue has changed.
I just picked up on the fact that the images are outputting correctly, but their not getting their corresponding captions, rather each image shows the caption from a different image having a lower ID number. The offset is not consistent, though. Sometimes it’s the caption from the previous image ID number, or 2.
I think this is the relevant part where there’s a problem:
<txp:image_info id='<txp:article_id />' type="caption" wraptag="figcaption" />
Anyone see what’s amiss?
Now that I stare at it more, this doesn’t even make any sense to me:
id='<txp:article_id />'
I’m not sure how I came up with that part. But if I take it out, I don’t get any captions at all.
Offline
Re: Nested if tags to employ a custom field as selector attribute
I guess it should be
<txp:image_info id='<txp:custom_field name="article_image" />' type="caption" wraptag="figcaption" />
which makes me think that there should be an easier way to output article image(s) id.
Offline
Re: Nested if tags to employ a custom field as selector attribute
etc wrote #309998:
id='<txp:custom_field name="article_image" />'
Bingo. I would have never thought to try that. THANK YOU!
which makes me think that there should be an easier way to output article image(s) id.
Yes, I just spent the last 20 minutes going through the Tag Reference trying to figure out how it could be done. Seems like an obvious tag missing.
Offline
Re: Nested if tags to employ a custom field as selector attribute
<txp:article_image>
has traditionally been for only outputting a nicely formatted <img>
tag. Historically, this was based one the one-image-per-article relationship (either an image ID or a URL, incidentally).
When <txp:images>
came along and permitted a list of image IDs to be put in the Article Image field, things got a bit weird becasuse you could iterate over the list of images and do stuff with them (more in a moment), but the <txp:article_image>
tag hasn’t kept pace. It’ll probably just fall over, or render the first one in the list – think it’s the latter.
Over the ages I have considered adding a way to get the raw value from the article image field, but since the <txp:custom_field>
hack works there’s been no pressing need. Do we need another tag, or a format
attribute to <txp:article_image />
that’ll ‘switch’ between the differrent formats (default is based on the type of thing it finds in the field itself, like now), or can we let it just rot since there are better ways to make images now?
Which brings me to…
etc wrote #309998:
there should be an easier way to output article image(s) id.
In this case it can be done by iterating over the (sole, in this case) image in the field:
<txp:images><txp:image_info type="id" /></txp:images>
Is that better than the <txp:custom_field>
hack? Probably not.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Nested if tags to employ a custom field as selector attribute
From a fast look at the code, you must be able to use <txp:images />
container without recurring to article_image
field, calling <txp:image_info />
etc inside it without id
attribute. But I haven’t tried.
Edit: Stef types 10 times faster than I :-)
Offline