Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: smd_wrap: conditionally wrap stuff with tags and labels
@ Maniqui
+1 for the leading blank space and textile transform. Or otherwise create a new mode “textile-inline”.
@ Bloke
For info:
with smd_wrap 0.2beta
and smd_macro
, {remplacment}
tags are still considered empty. Nothing is wrapped
This is not the case with smd_wrap 0.1
and smd_wrap_all 0.2beta
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
maniqui
Thanks for the detailed report, as ever. I’ll look into some fixes. Off the top of my head I have a feeling I know why they’re happening.
Firstly, Txp’s do_list()
strips spaces from stuff which probably means your replace
transform is being truncated unless you ‘protect the space’ with the closing pipe. I should use explode()
instead.
Secondly, in the textile case, the contents is probably being truncated too. Remember the default attribute for smd_wrap is trim="1"
which is removing the space first. Try it with trim="0"
and see if the paragraph tag is removed. I suspect it’ll render as expected (though the transform itself might strip spaces, I can’t remember — I hope it doesn’t or it’s a bug).
Not sure if there’s a solution as such, aside from making trim="0"
by default. Perhaps that’s better now we have smd_wrap_all as an option? Or perhaps smd_wrap_all should set trim="1"
while smd_wrap should set trim="0"
by default? Or is that too confusing?
sacripant wrote:
smd_macro
,{remplacment}
tags are still considered empty. Nothing is wrapped
Do you have an example please? I can then try and replicate what you’re seeing so I can investigate. Thanks.
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: smd_wrap: conditionally wrap stuff with tags and labels
Bloke
.
Totally forgot about the “trim” attribute, and setting it to 0
makes the difference. Thanks.
This lead me to discover that the textile transform won’t play nice when there are multiple lines (each one probably with leading spaces too) inside smd_wrap_all
.
So, a bit of googling taught me about the /m
modifier for regexs :D
Now, I share with you all the Ultimate Textilezer snippet:
<txp:smd_wrap_all transform="replace|regex|#^[ \t]+#m||, textile">
h3. {title}
{summary}
h4. Yeah, this line (and the above ones too!) had leading blank spaces, but it's cool, they will get textilized too.
chaooooooos paragraph
with leading spaces
or without them
# list item
# list
# a blank space in front? No prob! This is a list item too
## second level!
</txp:smd_wrap_all>
Enjoy!
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
maniqui
One for the scrapbook / plugin examples! Brilliant, thanks.
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
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
Bloke a écrit:
Do you have an example please? I can then try and replicate what you’re seeing so I can investigate. Thanks.
I tried smd_macros with a vevent (hcalendar microformat).
My Macro definition :
<div class="vevent">
<txp:smd_wrap transform="textile" trim="0" wraptag="h3" class="summary" item=" {title}" />
<div class="meta meta-event">
<p class="date_duration">
<txp:smd_wrap label="Start" labeltag="strong" wraptag="abbr" class="dtstart" attr="title|{start}" transform="date|%b %Y" item="{start}"/><br />
<txp:smd_wrap label="End" labeltag="strong" wraptag="abbr" class="dtend" attr="title|{end}" transform="date|%b %Y" item="{end}"/>
</p>
<p class="location">
<a class="include" href='#<txp:smd_wrap transform="sanitize|url_title" item="{lieu}" />-hcard'>{lieu}</a>
</p>
</div>
<txp:smd_wrap transform="textile" wraptag="div" class="description">{description}</txp:smd_wrap>
</div> <!-- .vevent -->
And if i write (in write tab)
notextile.. <txp:vevent
lieu="Bloke's Home"
start="2012-02-30"
end="2012-03-01"
title="Textpattern Drinks"
description="
Cool, fiesta _chez Bloke_ !!
"/>
Résultat :
<div class="vevent">
<div class="meta meta-event">
<p class="date_duration">
<br />
</p>
<p class="location">
<a class="include" href='#-hcard'>Bloke's Home</a>
</p>
</div>
</div> <!-- .vevent -->
{remplacment}
tags are still considered empty.
With smd_wrap_all
everything works.
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
sacripant
Thanks for the example.
With
smd_wrap_all
everything works.
Yes, it will. By default, <txp:smd_wrap>
only works if the item/form/container has <txp:...>
tags in it. If you’re just wrapping a {replacement}
you need <txp:smd_wrap_all>
because it treats data as a raw stream of info, not a collection of tags.
Essentially:
<txp:smd_wrap>
behaves like<txp:chh_if_data>
<txp:smd_wrap_all>
behaves like<txp:smd_wrap>
did in v0.10
Shout at maniqui if this is wrong (he convinced me change it!), or — probably more productive — let me know if you think this situation can be improved by better naming or altering some of the default attributes.
Last edited by Bloke (2012-02-16 16:21:35)
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: smd_wrap: conditionally wrap stuff with tags and labels
I started my tests with “smd_wrap 0.1”. Until arriving at {lieu} (place):
<p class="location">
<a class="include" href='#<txp:smd_wrap transform="sanitize|url_title" item="{lieu}" />-hcard'>{lieu}</a>
</p>
How to wrap {lieu} with a
and p
?
<txp:smd_wrap wraptag="p" class="location">
<a class="include" href='#<txp:smd_wrap transform="sanitize|url_title" item="{lieu}" />-hcard'>{lieu}</a>
</txp:smd_wrap>
Don’t work, if {lieu} is empty, p
and a
are displayed. Then I update smd_wrap
to 0.2b. but {lieu} are not recognized.
The solution is to ship {replacement} tag in <txp:variable /> :
<txp:variable name="lieu" value="{lieu}" />
<txp:smd_wrap wraptag="p" class="location">
<a class="include" href='#<txp:smd_wrap_all transform="sanitize|url_title" item="{lieu}" />-hcard'><txp:variable name="lieu" /></a>
</txp:smd_wrap>
OK.
if you think this situation can be improved by better naming or altering some of the default attributes.
Mmmmh,
Never used {tokken}
in your plugins. Only <txp/>
tags :¬D
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
[Edit 2012-02-27-0811—the below has been improved upon
Hi Stef & fellow TXPers,
I wanted the ability to easily add subtitles to section names. And I wanted to do it by adding copy to the Section title
like this My section name _my section subtitle_
.
I achieved this with the following code:
<txp:smd_wrap transform="replace||</p>|">
<txp:smd_wrap transform="replace||<p>|">
<txp:smd_wrap transform="textile">
<txp:section title="1" link="1" />
</txp:smd_wrap>
</txp:smd_wrap>
</txp:smd_wrap>
The multiple smd_wrap
s are because adding Textile support wraps the content in a <p></p>
tag and I don’t want a <p></p>
tag.
Is there a more elegant way of doing this with smd_wrap
? I checked the docs and tried a few methods but this is the only way I’ve been able to work out (not complaining, I LOVE that I can do this!).
Thanks for the plugin Stef, cheers all, -Alan
Last edited by alanfluff (2012-02-27 13:12:21)
At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
Yes, you can chain transforms inside the tag and do the opening and closing p-tag replace in one operation:
<txp:smd_wrap transform="textile,replace|regex|'<\/?p>'|"><txp:section title="1" link="1" /></txp:smd_wrap>
TXP Builders – finely-crafted code, design and txp
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
Thanks jakob!
I didn’t realize I could do that, excellent. I’ll go and read up (again) on regex ;) Cheers! -Alan
At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A
Offline
#84 2012-02-24 20:57:25
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,310
Re: smd_wrap: conditionally wrap stuff with tags and labels
alanfluff wrote:
And I wanted to do it by adding copy to the
Section title
like thisMy section name _my section subtitle_
.
That’s clever thinking! I like this kind of duplicated use of text inputs :) Thanks for sharing this, Alan! We’ve now three new methods for enriching section information gathered here in one day.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline