Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Offline
Re: custom field value as a variable for link and category name
etc wrote #319676:
The future is coming.
Hi Oleg,
I’ve tried this out now and find that I am now not getting custom_field filtering at all, with or without the attribute. Checking the debug trace, the SQL statement has no custom field filter. Just section, limit and the usual date and status conditions.
Looking at the code, is the syntax correct with if and switch run into each other in the same if-condition? Maybe it just looks unfamiliar to me. I tried putting the switch within the if brackets and dmp-ing messages to see which case applies for
<txp:article_custom article_front_display="Yes" section="english" limit="1"> … </txp:article_custom>
(where “article_front_display” is a yes/no custom field) and get the case that’s not covered: switch case = true; if case = else (i.e. if and elseif are both not met). Does that help at all?
TXP Builders – finely-crafted code, design and txp
Offline
Re: custom field value as a variable for link and category name
jakob wrote #319762:
is the syntax correct with if and switch run into each other in the same if-condition?
It’s syntactically correct – an if()
doesn’t need a brace if there’s “one statement” within it – and the switch counts as such in this scenario – but since we’re adhering to PSR-2 wherever we can, we should use braces for the if() { ... }
construct for clarity. In the same way we shouldn’t be using:
if ($condition) return;
and:
if ($condition) continue;
in the code any more. Although it takes up more space, we should be using:
if ($condition) {
continue; // Or return or whatever
}
It simply makes it easier to read and introduces fewer potential mistakes if someone decides in future that we need another action inside that conditional, because:
if ($condition) $counter++; continue;
or:
if ($condition) $counter++;
continue;
is the same as:
if ($condition) {
$counter++;
}
continue;
which is highly likely not what was intended.
As for the reason it’s not working for you and bringing in the custom field data, I’ll have a play with it when I get a chance, though Oleg will probably beat me to 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
Re: custom field value as a variable for link and category name
D’oh! Of course, switch
comparison is not strict, so everything not empty matches true
. Thanks Julian, corrected.
Offline
Re: custom field value as a variable for link and category name
Incidentally, I have removed unregistered tags fallback, but maybe it’s time anyway? Most plugins should have already updated their code.
Offline
Re: custom field value as a variable for link and category name
etc wrote #319766:
Incidentally, I have removed unregistered tags fallback, but maybe it’s time anyway? Most plugins should have already updated their code.
Yeah, spotted that… *frantically checks plugin code* … Uh-oh.
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
Re: custom field value as a variable for link and category name
etc wrote #319765:
D’oh! Of course,
switch
comparison is not strict, so everything not empty matchestrue
. Thanks Julian, corrected.
Thank you so much! That restores functionality :-)
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”.
Incidentally, I have removed unregistered tags fallback, but maybe it’s time anyway? Most plugins should have already updated their code.
Yes, that’s about time. One minor thing: that would be great as a separate commit with an appropriate description for better findability later though, as it will no doubt result in forum queries. Sometimes it’s useful to be able to point to when things changed.
As that was the most recent commit, perhaps you can still revert and re-commit separately?
Bloke wrote #319767:
Yeah, spotted that… frantically checks plugin code … Uh-oh.
You have such a tremendous collection, you may still have one or two without registered tags. Thanks for the explanations above. Makes sense!
TXP Builders – finely-crafted code, design and txp
Offline
Re: custom field value as a variable for link and category name
jakob wrote #319768:
you may still have one or two without registered tags.
I count five, excluding forks. Not as bad as I thought. I’ll tend to those asap.
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
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
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
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
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