Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-03-31 10:50:20

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Attributes for txp:yield?

While looking at the shortcode examples in Destry’s additions to the docs, I wondered if there’s a case for some additional attribute for txp:yield to simplify insert code if the yield name exists.

Currently we have this kind of thing:

<figure<txp:if_yield name="class"> class="<txp:yield name="class" />"</txp:if_yield>>

But could we have something like

<figure<txp:yield name="class" prefix='class="' suffix='"' />>

or …

<figure<txp:yield name="class" wrap_attribute="class" />>

or something else along those lines?

The first example is probably more flexible and would be a common scenario but the quote as a string in quotes requires some care.


TXP Builders – finely-crafted code, design and txp

Offline

#2 2018-03-31 11:17:11

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Attributes for txp:yield?

That’s how I would do it in Destry aside example:

linkquote form

<txp:linklist id='<txp:yield name="id" />'>
    <q><txp:link_description escape="tidy, textile" /></q> 
    <p class="sig"><txp:yield name="name" /><span class="sourcelink"><a href="<txp:link_url />"><txp:link /></a></span></p>
</txp:linklist>

Form call

<txp::linkquote id="1, 2" wraptag="aside" class="someclass" />

This way, wraptag and class are processed as global attributes. No need for extra stuff.

Last edited by etc (2018-04-01 10:10:39)

Offline

#3 2018-03-31 12:24:02

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Attributes for txp:yield?

Good point, though my/the example with class was poorly chosen because it’s also a global attribute. For other cases, the ability to do prefix/suffix or to wrap would be useful.

Good point too about Destry’s example. There is, however, also an argument for making the shortcode as simple as possible for non-techie users. I’m not stretching admin users too much to look up a link id and write <txp::linkquote id="23" /> in their article body, but if I ask them to add all the other attributes too, they just send me an email asking me to do it ;-)


TXP Builders – finely-crafted code, design and txp

Offline

#4 2018-03-31 12:31:26

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Attributes for txp:yield?

I’ve got no clients :-) What you are suggesting looks more like splitting the global wraptag into prewrap and postwrap parts. That’s quite useful and easy to do, we just need good names. wrap_attribute is an interesting idea too, but again, it would be global rather than <txp:yield />-specific. Needs some thinking first.

Offline

#5 2018-03-31 13:09:35

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

Re: Attributes for txp:yield?

If I’m following this conversation correctly, and I’m not entirely sure, then I might just add this notion to the stew…

Another doc I had to revise was this one, found under the Tag basics pages, which I wrote a while back, before the new short-tags and shortcodes functionality was released.

At the time, that doc was titled, for lack of better thinking, Short-form vs. long-form tag structure. The subject of that page is how you can integrate HTML elements as Textpattern tag attributes, and how that can save against markup volume. But it was quite confusing as labeled and referenced once the new “short-tag” stuff came out. I think the new title is distinctive enough now and perhaps even more accurate concept-wise.

My point, as that doc goes a way to describe, is that different people may have different preferences — or even learning needs — as to how to use tags. Not everyone is comfortable with the integrated approach to building tags (and maybe not with the new short-tags either). I’m still not. It’s often easier for me to keep the HTML markup separate from the Textpattern markup just to see what’s actually going on.

So, whatever it is you guys are cooking up, I think, at least as it concerns user documentation, we need to keep it introductory and fundamental at first, then show alternate/advanced approaches to achieving the same things in later sections of the example pages, which is kind of what I aimed to do in the Aside-quote shortcode doc.

Having said all that, etc, are you suggesting I should edit that shortcode example so the shortcode markup and associated tag looks like this?

I find that more complex to understand, personally, despite the obvious savings on characters; me not being someone who messes with Txp machinery much.

But I think it’s a perfectly valid option to add as another section at bottom of page. That work?

Offline

#6 2018-03-31 13:36:33

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Attributes for txp:yield?

etc wrote #310500:

I’ve got no clients :-) What you are suggesting looks more like splitting the global wraptag into prewrap and postwrap parts. That’s quite useful and easy to do, we just need good names. wrap_attribute is an interesting idea too, but again, it would be global rather than <txp:yield />-specific. Needs some thinking first.

I think pre and post wrap attributes would be an excellent addition, and even better as global attributes.

In terms of naming, the liquid templating languages uses prepend and append which I think are both easily understandable and not solely tag related, giving you (using a different example this time):

<a href="<txp:image_url />"<txp:yield name="original" prepend=' data-original="' append='"'/>> … </a>

TXP Builders – finely-crafted code, design and txp

Offline

#7 2018-03-31 13:56:23

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

Re: Attributes for txp:yield?

I’ve updated the aside-quote doc to add etc’s markup as another advanced option. I actually like it now because the entire doc somewhat covers the scope of possible tag tricks and talismans to achieve the same result: regular and short-tag usage, mixed or integrated usage (global attributes for HTML), and short-tag and integrated usage.

A lot of roads lead to the doghouse.

Offline

#8 2018-03-31 14:11:35

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Attributes for txp:yield?

All valid points, especially on making shortcodes straightforward to use. I’ve got no magic solution, just exposing the thing from “inside”.

Destry wrote #310503:

Not everyone is comfortable with the integrated approach to building tags (and maybe not with the new short-tags either). I’m still not. It’s often easier for me to keep the HTML markup separate from the Textpattern markup just to see what’s actually going on.

That’s totally fine (and faster to process, btw), but can result in empty blocks. Say,

<p><txp:variable name="text" /></p>

will always output <p>...</p> block, even when <txp:variable name="text" /> is undefined or empty, unlike

<txp:variable name="text" wraptag="p" />

Having said all that, etc, are you suggesting I should edit that shortcode example so the shortcode markup and associated tag looks like this?

Probably not, that’s less convenient for frequent use, as you rightly say. We should find something better.

jakob wrote #310504:

<a href="<txp:image_url />"<txp:yield name="original" prepend=' data-original="' append='"'/>> … </a>...

Hmm, I don’t really like it if we speak on clients behalf. It’s as weird as

<a href="<txp:image_url />"<txp:evaluate> data-original="<txp:yield name="original" />"</txp:evaluate>> … </a>

Anyway, you put this code inside a form, which is normally not clients job. A client wants just an easy way to use a shortcode form, without any need to look inside.

Offline

#9 2018-03-31 16:03:52

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

Re: Attributes for txp:yield?

etc wrote #310507:

(and faster to process, btw)

That’s a worthy point to communicate in docs, strategically. It certainly affirms how I will be doing things in most cases. ;)

<p><txp:variable name="text" /></p>... will always output <p>...</p> block, even when <txp:variable name="text" /> is undefined or empty, unlike <txp:variable name="text" wraptag="p" />...

That is also a worthy point to keep a thumb on in docs. A good example when an integrated approach to a tag string is worthwhile.

Thanks.

Offline

#10 2018-03-31 16:11:27

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Attributes for txp:yield?

etc wrote #310507:

Hmm, I don’t really like it if we speak on clients behalf … Anyway, you put this code inside a form, which is normally not clients job.

Sorry, I should have been clearer: this particular aspect has nothing to do with clients.

My interest was in making code a bit easier to read. Up to now – if we code defensively – we end up with a lot of things like:

<txp:if_variable name="my_variable" value=""><txp:else /> … <txp:variable name="my_variable" /> … </txp:variable>

and frequently I have various instances of smd_wrap (or smd_wrap_all) in my code too to stop the if_variable responding incorrectly when people leave spaces in a field or when I want to write a more complex bit of code on several lines rather than in one long mind-boggling line. Use this a few times, in conjunction with some other if … else conditional, and you quickly end up with complicated code littered with txp:else tags.

The introduction of txp:evaluate test="tag-name" is already a nice readability improvement over if_variable … else constructions containing larger blocks of code. And the new escape="trim" / ="tidy" / ="tag-name" all help reduce the need for smd_wrap. Both are great new additions!

My question in the other thread about whether one could do <txp:if_variable name="my_variable" not value=""> … </txp:if_variable> (which we can’t as I understand it) was to see if one could do if variable is empty more easily and lose a lot of those txp:else tags.

The idea of prepend="place-in-front" and append="place-after" (or whatever they may be called) has a similar aim: reduce txp:if_variable name value (else) … txp:variable … /txp:variable to one single tag with txp:variable name prepend append.


TXP Builders – finely-crafted code, design and txp

Offline

#11 2018-03-31 17:33:27

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

Re: Attributes for txp:yield?

etc wrote #310493:

That’s how I would do it in Destry aside example:

@linkquote@ form

<txp:linklist id='<txp:yield name="id" />'>...

Form call

<txp::linkquote yield="id, name" id="1, 2" wraptag="aside" class="some_class" />...

This way, wraptag and class are processed as global attributes. No need for extra stuff.

Looking at this closer, I think there might be a discrepancy here against what I intended.

In my original example, the name="" attribute wasn’t pulling from a link data item, it was a free attribute to type in any name value a person wants for that given aside. If not used, nothing outputs.

I don’t think that’s how this integrated example of etc’s is designed, though. Am I wrong?

Probably my poor choice of using “name” as a custom attribute wasn’t good agaist the yield tag, which might have had etc confused.

I think I better remove that last example from the doc. I don’t feel it’s a worthy option to suggest to people anyway when starting out. A bit too complex, maybe. But if we can fix it, I’ll leave it.

Offline

#12 2018-03-31 19:17:03

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Attributes for txp:yield?

jakob wrote #310515:

The idea of prepend="place-in-front" and append="place-after" (or whatever they may be called) has a similar aim: reduce txp:if_variable name value (else) … txp:variable … /txp:variable to one single tag with txp:variable name prepend append.

Ok, makes sense and nice idea imo, I like it. As to implementation, we can hack wraptag attribute. Currently, setting wraptag="not a word" would produce the invalid

<not a word>...</not a word>

We could detect such cases and consider them as prepend...append pattern, splitting the attribute by some special string, e.g.

wraptag=' class="..."' or wraptag=' class="*"'

The splitting string (... or * above) should be easy to remember and unlikely to be part of prepend/append strings. The poll is open.

Offline

Board footer

Powered by FluxBB