Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2019-10-18 13:05:28

etc
Developer
Registered: 2010-11-11
Posts: 3,939
Website

Re: custom field value as a variable for link and category name

jakob wrote #319768:

I haven’t tried the attribute-less variant yet. I realise I misunderstood its use. It’s not “if there’s any value for it” but “if it’s the same as the current article” or “if it’s been passed as an urlvar”.

That’s something we can change yet, because it’s unofficial. “If there’s any value for it” actually looks more logical and predictable, but then filtering by url vars becomes more verbose. A poll?

As that was the most recent commit, perhaps you can still revert and re-commit separately?

GitHub does not seem to propose a revert link any more, and I’m not familiar with git cli :-(

Bloke wrote #319769:

I count five, excluding forks. Not as bad as I thought. I’ll tend to those asap.

Feel free to revert :-)

Offline

#22 2019-10-18 13:36:44

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

Re: custom field value as a variable for link and category name

etc wrote #319770:

Feel free to revert :-)

Manually part-reverted and then re-committed your changes as an atomic commit. That makes things potentially easier to yank this commit out if there’s backlash.


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

#23 2019-10-18 13:56:53

etc
Developer
Registered: 2010-11-11
Posts: 3,939
Website

Re: custom field value as a variable for link and category name

Bloke wrote #319771:

Manually …

Oops.. sorry! I thought there was some magic git command for everything.

Finally I find @jakob valueless cf attributes interpretation as “not empty” more logical. If we need to enable filtering by URL vars, we can introduce some searchby attribute.

Offline

#24 2019-10-18 14:07:19

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

Re: custom field value as a variable for link and category name

etc wrote #319773:

I thought there was some magic git command for everything.

If only! It’s pretty easy to revert atomic commits as you can just git revert <commit-id> or git cherry-pick <commit-id1 commit-id2 ...> but if a commit contains multiple things and you want to undo part of it, the only way is with copy and paste.

I just yanked a few chunks of the code I wanted from the old commit into the text editor to set the file how it was, committed, then used ‘undo’ a few times in Sublime Text until the code matched your previous commit, and then re-committed that. No biggie.


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

#25 2019-10-18 15:33:37

etc
Developer
Registered: 2010-11-11
Posts: 3,939
Website

Re: custom field value as a variable for link and category name

Ok, since <txp:article(_custom) /> already accepts match attribute, let’s abuse it. This commit introduces the following filters:

<txp:article_custom custom1 match="custom2" />

will match all articles with not empty custom1 field and with custom2 matching the current article’s custom2 in article context or URL var custom2.

Offline

#26 2019-10-18 15:37:47

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,938
Website

Re: custom field value as a variable for link and category name

etc wrote #319773:

Oops.. sorry! I thought there was some magic git command for everything.

Finally I find @jakob valueless cf attributes interpretation as “not empty” more logical. If we need to enable filtering by URL vars, we can introduce some searchby attribute.

Dunno. You might be right that valueless cf attributes should simply mean “a value exists”.

Then again, I found the prospect you dangled of being able to do ‘intelligent’ multi-filtering just on the basis of whether an url var was supplied quite enticing. The could be quite powerful. It just has to be controllable by the developer; you don’t want people doing their own non-permitted filtering via urlvars. Maybe some predefined reserved value terms such as custom_field_name="urlvar:varname" or custom_field_name="article:parent"

Bloke wrote #319774:

It’s pretty easy to revert atomic commits as you can just git revert <commit-id>

Thank you! I just thought it would be useful for this “momentous” event to be traceable again at some time in the future. I think you can just revert the whole commit, then recommit as two separate commits. Either way, it’s all good now. Thank you!


TXP Builders – finely-crafted code, design and txp

Offline

#27 2019-10-18 15:45:08

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,938
Website

Re: custom field value as a variable for link and category name

etc wrote #319776:

This commit introduces the following filters:

<txp:article_custom custom1 match="custom2" />...

will match all articles with not empty custom1 field and with custom2 matching the current article’s custom2 in article context or URL var custom2.

Can you do multiple matches with that? Maybe as comma-separated custom fields…


TXP Builders – finely-crafted code, design and txp

Offline

#28 2019-10-18 15:50:42

etc
Developer
Registered: 2010-11-11
Posts: 3,939
Website

Re: custom field value as a variable for link and category name

jakob wrote #319778:

Can you do multiple matches with that? Maybe as comma-separated custom fields…

Yes we can :-) It’s default value is Category1, Category2, historically joined by OR, but cf and other filters are joined by AND.

It just has to be controllable by the developer; you don’t want people doing their own non-permitted filtering via urlvars. Maybe some predefined reserved value terms such as custom_field_name="urlvar:varname" or custom_field_name="article:parent"

Txp authors can set a filter anyway, via custom1='<txp:page_url type="custom1" />', so nothing new here. And site visitors will be able to filter only by attributes in match.

Offline

#29 2019-12-22 17:34:49

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,938
Website

Re: custom field value as a variable for link and category name

I’ve been forced to do an emergency upgrade of a really ancient site (v4.0.8) because the host upgraded mySQL and no-one can log in now. It was long overdue anyway but a central aspect of this particular site is a very old version of Gerhard’s glz_custom_field from the days when he had some public-side tags. There were two parts:

  • a select drop-down that populated the options from custom fields that could hold multiple values, like an array of checkboxes and passed them as POST variables.
  • a parallel tag to txp:article that could filter via custom fields and match a value in a custom_field that holds multiple values separated by a | pipe.

I tried to replicate this using the new custom field filtering in txp 4.8.0 but have come up against a problem. At first I thought I had it working but when checking against the public site (still the old version) I got different query results.

You mention multiple matches above, but if I’ve understood your example above correctly, that means filtering results by multiple attributes (categories, more than one custom field, etc.) at once (which is certainly useful).

In this case I need to test if the url query matches a value in a series of values. Is there a way to match against multiple values within a field using the standard tag(s)? Or is this a query I need to construct using smd_query?


TXP Builders – finely-crafted code, design and txp

Offline

#30 2019-12-22 19:44:15

etc
Developer
Registered: 2010-11-11
Posts: 3,939
Website

Re: custom field value as a variable for link and category name

jakob wrote #320658:

In this case I need to test if the url query matches a value in a series of values. Is there a way to match against multiple values within a field using the standard tag(s)?

If URL query parameter is an array (like param[]=one&param[]=two), txp will transform it into

(param LIKE 'one' OR param LIKE 'two')

If you manage to somehow insert %one% and %two% into URL, this could work provided they don’t make part of longer values.

Offline

Board footer

Powered by FluxBB