Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2020-06-24 14:58:38

etc
Developer
Registered: 2010-11-11
Posts: 4,259
Website GitHub

Re: Bibliography management

Bloke wrote #323978:

Dammit, sorry. <txp:link_name> doesn’t use global escape, so trim doesn’t work. Oleg: Is it easy to retrofit without breaking backwards compatibilty in 4.8.2?

It should work, but &nbsp; is not trimmed by PHP trim() function. A space would work, or some other symbol (say _) that you can trim with

<txp:link_name trim="_" ... />

Offline

#26 2020-06-24 15:09:49

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

Re: Bibliography management

etc wrote #323979:

A space would work, or some other symbol (say _) that you can trim with

Noted.

I’ll sit tight for the time being. I’ve plenty of other things to do.

Offline

#27 2020-06-24 15:29:59

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,285
Website GitHub

Re: Bibliography management

Oh yeah, sorry, I misread Destry’s post. Didn’t spot that he was using &nbsp;.

For some reason, I thought we had to pass the tag’s output through txp_escape() to get it to benefit? Cool if we don’t and it works now.

So, Destry, does it work if you use a simple space character as the link_name then escape="trim"? Or use a single underscore or some other character that you don’t use in your regular titles, which you can then remove with trim="YourCharacterHere" prior to it being tested to see if it returns anything.


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

#28 2020-06-24 17:04:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,285
Website GitHub

Re: Bibliography management

etc wrote #323969:

Any reason why?

Also, I just checked it out. Presumably if we didn’t have at least one required field on the Edit Link panel, then you could just click Add Link->Save, Add Link->Save, … and it’d create you a bunch of unnamed links with no content and no fields set beyond the datestamp. Is that okay?

If there was a way of making sure that at least one of the fields was set then we might be able to get away with making the Name optional. But how would we display that requirement for good UX? And what if someone edits a link and blanks out all the content then Saves it?

I think for those reasons and for the ‘default plainlinks Form’ thing I mentioned earlier, we elected to have the Name required. Not saying it’s set in stone, but I think that’s the reason.

Now, one could argue that if you’re making a link, then the URL should be required. But I’ve just worked on a site where that’s not the case. I’m using Links for the list of people that contributed financially to the site’s cause, and not all of them have a website.

I made entries for them all, used the Sort value field as the name of an image I uploaded to represent the contributor’s logo, used the Title for their company name and a description to say how they contributed/thanks. But if they didn’t have a website, they were displayed on the front end without a clickable link.

Thus we can’t really stipulate that a link should contain a URL, although most of the time it would so it’s probably cleaner to do that than make the name required. Dunno. I can hack around it if this was changed using the same trick as above to put in a space as the URL then trimming it and checking 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

#29 2020-06-24 20:51:22

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

Re: Bibliography management

I’ve tested the updated plugin now and it should now work ok (a db backup is always a good idea :-)

You can find the multiple field version here

When you install it, it adds five new custom fields but only shows the ones you actually give a name in the Admin › Preferences (just like the regular article custom fields). If you install it over the earlier version:

  1. Flick it off and on again and it will copy over the custom field data you had into the first custom_field and delete the old legacy column from the db.
  2. Go to Admin › Preferences › Link custom fields and give the first custom field and field name.

Your existing tag should now work again, but you can use name="your_field_name" to specify it explicitly (it defaults to the first field if no name is given).

You can use the wraptag, escape and default attributes from txp 4.8 and there’s also a conditional field, e.g.:

<txp:jcr_link_custom name="your_field" wraptag=" (<+>)" />

will output a space and then the value in brackets if a value has been specified (where <+> is a placeholder for the contents).

You can also do:

<txp:jcr_if_link_custom name="image_id">
    <txp:image id='<txp:jcr_link_custom name="image_id" />' limit="1" />
<txp:else />
    <txp:link_name />
</txp:jcr_if_link_custom>

which will output an image only if there is one, otherwise the link_name, or

<txp:jcr_if_link_custom name="status" value="new">
    <txp:link_name /> <span>NEW!!</span>
</txp:jcr_if_link_custom>

and so on…

EDIT: updated GitHub links.


TXP Builders – finely-crafted code, design and txp

Offline

#30 2020-06-24 21:59:28

etc
Developer
Registered: 2010-11-11
Posts: 4,259
Website GitHub

Re: Bibliography management

Bloke wrote #323983:

If there was a way of making sure that at least one of the fields was set then we might be able to get away with making the Name optional. But how would we display that requirement for good UX? And what if someone edits a link and blanks out all the content then Saves it?

This looks handled in link_save() function:

    if ($linkname === '' && $url === '' && $description === '') {
        link_list(array(gTxt('link_empty'), E_ERROR));

        return;
    }

UX-wise, we could add a bit of JS to ensure at least one of these fields is set client-side, but it’s probably an overkill. Who would ever want to create an ‘empty’ link?

Offline

#31 2020-06-24 22:28:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,285
Website GitHub

Re: Bibliography management

etc wrote #323989:

UX-wise, we could add a bit of JS to ensure at least one of these fields is set client-side, but it’s probably an overkill. Who would ever want to create an ‘empty’ link?

True, it was hypothetical! I’m happy to knock the required status on the head IF we can:

  1. Display ‘unknown’ or something in the Links panel if the name is empty.
  2. Figure out a better solution for the tpt_link, link_name and linkdesctitle tags. They should not assume that the name exists and instead return gTxt('unknown') (or ‘unset’ or something) if it’s missing.

The trouble at the moment is that those three tags pass the linkname directly to tag() when constructing the anchor. If tag() receives empty content it skips the tag creation. That’s not what we want, is it? Uhhh, is 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

#32 2020-06-25 04:29:51

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,615
Website GitHub Twitter

Re: Bibliography management

etc wrote #323989:

Who would ever want to create an ‘empty’ link?

I would:) I’m using the links panel in creative ways. We discussed this back on 4.7 I think, and I had to add hashes (#) to all my empty links.


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Online

#33 2020-06-25 06:15:46

etc
Developer
Registered: 2010-11-11
Posts: 4,259
Website GitHub

Re: Bibliography management

colak wrote #323994:

I would:) I’m using the links panel in creative ways. We discussed this back on 4.7 I think, and I had to add hashes (#) to all my empty links.

By ‘empty’ I meant ‘no name/URL/description’, which leaves you with id, category and timestamp. You must be too creative to get any use of it :-)

Bloke wrote #323991:

The trouble at the moment is that those three tags pass the linkname directly to tag() when constructing the anchor. If tag() receives empty content it skips the tag creation. That’s not what we want, is it? Uhhh, is it?

We should ask the creative spirits among us what they expect these tags to output when the name is empty. The rest is just code.

Offline

#34 2020-06-25 06:43:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,285
Website GitHub

Re: Bibliography management

etc wrote #323995:

We should ask the creative spirits among us what they expect these tags to output when the name is empty.

*summons creative spirits*

Ummm:

  1. Skip output of entire link if name empty.
  2. Replace empty name with a fixed string (e.g. unnamed) and display that.
  3. Replace empty name with something ‘invisible’ and display it, so that tag() still renders something. &nbsp; is tempting but escape="html" will render it verbatim, which is probably not what we want.
  4. Something else…

Cast your votes/ideas please.


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

#35 2020-06-25 06:43:52

gaekwad
Multi-hyphenate
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,531
GitHub

Re: Bibliography management

etc wrote #323995:

You must be too creative to get any use of it :-)

Yiannis is actually a wizard, complete with a mysterious cloak and pointed hat.

Offline

#36 2020-06-25 09:16:30

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,615
Website GitHub Twitter

Re: Bibliography management

Bloke wrote #323998:

Something else…

Maybe have the URL? ie equivalent to "$":http://domain.tld with rel="external" if needed.


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Online

Board footer

Powered by FluxBB