Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
article_custom with EvalElse
<txp:article_custom section="articles" wraptag="ul" break="li"> <txp:title /> <txp:else /> Articles not found </txp:article_custom>
For testing this idea was writen simple plugin aks_article
.
Changes in core, file textpattern/publish.php
Replace:
function article_custom($atts, $thing = NULL) { return parseArticles($atts, '1', $thing); }
to
function article_custom($atts, $thing = NULL) { $out = parseArticles($atts, '1', EvalElse($thing, true)); if (!$out) $out=parse(EvalElse($thing, false)); return $out; }
Last edited by makss (2012-05-18 09:04:02)
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: article_custom with EvalElse
Hi makss
Couldn’t this be achieved with a simple variable?
Something like
<txp:variable name="articlecustom" value='<txp:article_custom section="articles" />' />
<txp:if_variable name="articlecustom" value="">
Articles not found
<txp:else />
<txp:article_custom section="articles" />
</txp:if_variable>
Last edited by colak (2012-05-18 11:08:45)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: article_custom with EvalElse
colak wrote:
Couldn’t this be achieved with a simple variable?
Something like
The code works, but article_custom
performed twice, which increases the number of SQL queries to the database twice. If the page has a 5 – 7 of these blocks, then lost the speed of the website. The question of performance is important for me.
For a long time I used a different solution – plugin chh_if_data
. But this plug-in has its limitations and does not always work correctly.
I’m tired of a large number of nested tags, variables, if_s, plugins. So I try to make the code simpler to understand and reduce the number of used plugins, variables and tags.
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: article_custom with EvalElse
+1
And this is how a few smd_ plugins work.
Offline
Re: article_custom with EvalElse
The suggested change needs to be some more than just that. Checking parseArticles()’s output will just check what the results of the already parsed markup. For example following:
<txp:article_custom><txp:excerpt /><txp:else />No Articles.</txp:article_custom>
Returns No Articles. if none of the latest ten articles have an excerpt.
Instead of the clever, simple boolean check, the changes should apply to both doArticle() and doArticles() function, so that they can reliably tell when the executed database query results in zero rows. This could be potentially done by changing the functions to return false on “error”.
The thing I’m concerned about this change is usability and how easy this type of not-so-obvious condition nesting is to understand and read. I agree, this would be neat trick, but does it confuse things too much?
The primary issue that comes to my mind is, how do you make it clear that the fallback statement doesn’t accept article tags? The statement is inside an article tag, but plays with different rules. It might not be that obvious which tags can you actually use in the statement.
The second thing is that it’s not a condition statement, which makes reading the statement harder to those that are not familiar with option. How to make clear when the statement is actually shown? When there are no articles? When there is no resulting output?
And the third is the standardization. Same thing won’t work across all tags. How about when the user comes and wonders why the same doesn’t work with all Textpattern tags? If it’s implemented in article_custom, it should be supported by all and every list tag. In which point the change could actually apply to the parser itself, instead of the tag functions.
Offline
Re: article_custom with EvalElse
colak a écrit:
Couldn’t this be achieved with a simple variable?
It could, almost the way you wrote it, i.e:
<txp:variable name="articlecustom" value='<txp:article_custom section="articles" />' />
<txp:if_variable name="articlecustom" value="">
Articles not found
<txp:else />
<txp:variable name="articlecustom" />
</txp:if_variable>
Offline
Re: article_custom with EvalElse
In fact to go closer to what makss wanted
we could add a listform
<txp:variable name="articlecustom" value='<txp:article_custom section="articles" wraptag="ul" listform="just_title"/>' />
<txp:if_variable name="articlecustom" value="">
Articles not found
<txp:else />
<txp:variable name="articlecustom" />
</txp:if_variable>
Having said that, makss idea with Jukka’s thoughts will indeed be a good addition to the txp arsenal.
Last edited by colak (2012-05-18 17:13:42)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: article_custom with EvalElse
Gocom wrote:
The suggested change needs to be some more than just that. Checking parseArticles()’s output will just check what the results of the already parsed markup.
article_custom
– frontend tag. Does anyone like to look at a blank screen? If there is no output, then displays the contents of the block txp:else
<txp:article_custom><txp:excerpt /><txp:else />No Articles.</txp:article_custom>
Incorrect example. It is more logical to write like this:
<txp:article_custom excerpted="y" ><txp:excerpt /><txp:else />No Articles.</txp:article_custom>
or
<txp:article_custom><txp:if_excerpt><txp:excerpt /><txp:else /><txp:title /></txp:if_excerpt><txp:else />No Articles.</txp:article_custom>
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: article_custom with EvalElse
makss wrote:
article_custom
– frontend tag. Does anyone like to look at a blank screen? If there is no output, then displays the contents of the blocktxp:else
[…] Incorrect example
You are suggesting that is the intended behavior and it should show statement based on the parsed markup, not the actual retrieved article data? Can’t say that makes much sense to me. Seems to go whole way against obvious and what rest of the conditional tags behave.
Last edited by Gocom (2012-05-21 16:19:06)
Offline