Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2016-07-26 21:44:06

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: RFC: <txp:if_body> tag

Bloke wrote #300405:

Shortening if_custom_field to if_field would be fine by me, obviously retaining the old tag for backwards compatibility. But replacing all the other conditionals with it? I don’t know. If nothing else, it’s a lot of upheaval in terms of documentation to update everything to use the proposed tag.

That would require changes but I think it would be easier to document in the future and would avoid eternal requests about if_title, if_body, both, or about any future field. When a bug is as handy as the one told about <txp:if_custom_field>, it should become a feature… If <txp:if_field> would be more than just a bug, we could have only one tag for all fileds; we could deprecate <txp:if_article_image>, <txp:if_excerpt> and others and remove them in a future version.

We’ve introduced more if_first_* and if_last_* tags in 4.6 to align them with other things. A good idea? Not sure. But I’m not feeling positive about etc’s proposed if_position tag. However, I would be in favour of a pair of tags instead:

  • <txp:if_first> ... </txp:if_first>
  • <txp:if_last> ... </txp:if_last>

Those could default to the current context, e.g. if inside an images tag it would perform the same action as if_first_image / if_last_image. For nested conditionals or where you wanted to break out of the default context, a suitable attribute could allow you to do so, e.g.:

<txp:images>…

Just an idea.

Sure, <txp:if_first> and <txp:if_last> could be great; <txp:if_position> would be interesting if we could check for any position like <txp:if_position position="3">.
I also agree about the current context by default, and I’m not even sure that it is necessary to add an attribute to change that; I’m ok with the following (and it seems more clear too me — for now at least):

Your code:

<txp:images>

   <txp:if_first>
      First image: <txp:image />
   </txp:if_first>

   <txp:if_first type="article">
      <txp:excerpt />
   <txp:else />
      <txp:image_info />
   </txp:if_first>

</txp:images>

Mine:

(<txp:article>)

    <txp:images>
        <txp:if_first>
            First image: <txp:image />
        </txp:if_first>
    </txp:images>

    <txp:if_first>
        <txp:excerpt />
    <txp:else />
        <txp:images>
            <txp:image_info />
        <txp:images>
    </txp:if_first>

(</txp:article>)
gomedia wrote #300412:

I would say that it should apply to anything that’s generated inside <txp:if_first>...</txp:if_first>. If you just want to wrap the TRUE content – put a wraptag on the <txp:image /> tag.

Seems logical to me too, even it was not obvious at the first read.

Last edited by NicolasGraph (2016-07-28 07:37:52)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#26 2016-07-27 07:08:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: RFC: <txp:if_body> tag

NicolasGraph wrote #300418:

<txp:if_position> would interesting if we could check for any position like <txp:if_position position="3">.

Absolutely. Very handy.

I’m not even sure that it is necessary to add an attribute to change [context]; I’m ok with the following <snip>

OK, but your code doesn’t do the same as mine. Yours repeats the first image caption in the second block, and, crucially, isn’t as efficient as it requires repeating the images call. In this case it probably doesn’t require a second trip to the database but with other tags it might. There’d be no requirement to use the context attribute as it’d do what you expect most of the time, but it’d be there if you need 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

#27 2016-07-27 09:38:40

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: RFC: <txp:if_body> tag

Bloke wrote #300420:

OK, but your code doesn’t do the same as mine. Yours repeats the first image caption in the second block…

Right! :-/

…and, crucially, isn’t as efficient as it requires repeating the images call. In this case it probably doesn’t require a second trip to the database but with other tags it might. There’d be no requirement to use the context attribute as it’d do what you expect most of the time, but it’d be there if you need it.

Yes, that’s a good argument.
This context attribute just changes the way I see contexts (as something defined by Txp), I probably need to change my mind.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

Board footer

Powered by FluxBB