Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-15 11:27:12

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,415
Website

wraptag use clarification

Say I’m making a shortcode where I want to automatically prefix a data field with a short text String. .

Thanks to the recent thread on creating a bibliography, I’ve finally learned the beauty of this kind of thing: <txp:some_tag wraptag="String. <+>" />.

But what if I’m already using wraptag to provide a wrapping element: <txp:some_tag wraptag="element" />.

Can I somehow combine the two wraptag abilities in a single use of the wraptag="" attribute? Or must I go with this instead:

<element>String. <txp:some_tag /></element>

I’m fine with that, it’s straightforward and works. I just want to make sure I’m not missing some voodoo ability under the surface.

Offline

#2 2020-07-15 11:40:06

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,415
Website

Re: wraptag use clarification

A related question… What if a part of the String. is to be supplied by a new short-tag attribute value, a number, say, that would fill n, e.g. Figure {n}.

Can that be swung as part of the wraptag’s attribute value, whether or not the element is included in that case? (I can’t imagine how.)

Or is that also necessarily addressed by the long-form writing mentioned above, for example:

<figcaption><txp:if_yield name="number">Figure <txp:yield name="number" />. </txp:if_yield><txp:image_info id='<txp:yield name="id" />' escape="tidy,textile" /></figcaption>

Last edited by Destry (2020-07-15 11:43:34)

Offline

#3 2020-07-15 11:59:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: wraptag use clarification

You can only use wraptag for one type of reference at a time: an actual tag to wrap or to wrap it using the tie fighter <+> plus some arbitrary string content.

So if you want the tag to wrap the content, either surround the tie fighter with actual tags or put the tags inside your container:

<txp:some_tag wraptag="String. <element><+></element>" />

OR

<txp:some_tag wraptag="String. <+>">
   <element>content</element>
</txp:some_tag>

Both will do the same thing (assuming <txp:some_tag> can be used as a container).

If you were originally using wraptag to surround the entire tag then this is correct:

<element><txp:some_tag wraptag="String. <+>" /></element>

Last edited by Bloke (2020-07-15 12:02:50)


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

#4 2020-07-15 12:05:24

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,415
Website

Re: wraptag use clarification

Thanks for the confirmation.

Offline

#5 2020-07-15 12:16:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: wraptag use clarification

Pursuant to your second question, there’s nothing that prevents you from putting tags in attributes as normal, providing you keep the quoting rules intact. How about this to bake your noodle:

<txp:image_info id='<txp:yield name="id" />' escape="tidy,textile" wraptag='<figcaption><txp:yield name="number" wraptag="Figure <+>. " /><+></figcaption>'/>

:)

Last edited by Bloke (2020-07-15 12:17:42)


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

#6 2020-07-15 12:24:41

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,415
Website

Re: wraptag use clarification

Ha. The other long-form way to do it. Thanks.

I think I’ll stick to the conventional positioning, though. ;)

Offline

#7 2020-07-15 12:45:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: wraptag use clarification

Yeah, mine’s not the most readable of solutions!

The point is, you don’t necessarily need to use <txp:if_yield> if you’re using something as part of another attribute, OR you’re supplying a default value.

For example, if you were referring to images in a body of text, you could auto-number them. Each time you call the shortcode without the number attribute you could increment a counter and use that as the default:

<txp:if_yield name="number" not>
   <txp:variable name="autonumber" add="1" />
</txp:if_yield>
<txp:image_info id='<txp:yield name="id" />' escape="tidy,textile" wraptag='<figcaption><txp:yield name="number" default=''<txp:variable name="autonumber" />'' wraptag="Figure <+>. " /><+></figcaption>'/>

That’s probably not very useful as it stands, but it shows what can be done with a bit of creativity.

Last edited by Bloke (2020-07-15 12:46:26)


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

#8 2020-07-15 15:30:38

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,415
Website

Re: wraptag use clarification

Bloke wrote #324549:

you could auto-number them . . . increment a counter : <txp:if_yield name="number" not>...

Ah, that’s interesting, though.

If we can make the counter start at ‘2’ if article_image is used (then logically being ‘1’), we’re onto something I would employ stat in the almanossary (a project in the works).

Last edited by Destry (2020-07-15 15:31:27)

Offline

#9 2020-07-15 16:09:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: wraptag use clarification

Destry wrote #324552:

If we can make the counter start at ‘2’ if article_image is used

Hmmm, maybe (untested):

<txp:if_variable name="autonumber" not value>
   <!-- The auto-number isn't set yet -->
   <txp:if_article_image>
      <txp:variable name="autonumber" value="2" />
   <txp:else />
      <txp:variable name="autonumber" value="1" />
   </txp:if_article_image>
</txp:if_variable>
... rest of shortcode here...

I’m unsure if <txp:if_variable name="autonumber" not value> actually tests if the variable is unset or not. Might be a better way.

One thing you might need to do, depending on how you’re using the increment later in the shortcode, is set the initial values to one less than they are above. So when you hit the first <txp:variable add..> it increments the value from 1 (article image case) or 0 (non-article image case). Otherwise you might be one ahead all the time. It largely depends if you use the value, then increment it, or increment the value first then use it.


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

#10 2020-07-15 16:19:22

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,415
Website

Re: wraptag use clarification

Thanks. I’ll sit on this for a while because the manual way works pretty well if there are few images per article anyway. But if if I start seeing upwards of 5 images per article, then it seems worth investigating.

Offline

Board footer

Powered by FluxBB