Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2008-07-03 23:21:57

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Central storage for site-wide constants: Helpful?

I will try a rewrite on the code I already wrote based on Els example:

<txp:if_individual_article>

    <txp:variable name="match_category" value='<txp:category1 />' />

    <txp:variable name="have_match" value='<txp:article_custom limit="99" category='<txp:category1 />'>' />

    <!-- About "have_match" variable: I suppose that if there aren't 
           any articles on category1,  this will set value="" -->
    <!-- Then, I'm using article_custom similar 
           to what pgonly attribute does -->
    <!-- BTW... am I nesting three tags? 
           We are reaching the limits of the Universe -->

    <h3>Related Articles</h3>

    <txp:if_variable name="have_match" value="">
            <p>No related articles.</p>
    <txp:else />
            <txp:article_custom limit="99" category='<txp:category1 />' wraptag="ul" break="li">
                <txp:permlink><txp:title /></txp:permlink>
            </txp:article_custom>
    </txp:if_variable>

</txp:if_individual_article>

As in pgonly attribute, it may be a condition that the first <txp:article_custom /> is written almost-exactly (particularly, the attributes related to the query, like limit, and category) as the second one.
Does the code make sense?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#62 2008-07-03 23:48:57

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

Re: Central storage for site-wide constants: Helpful?

I’m still not quite sure what the goal is here but this example from maniqui looks closest. I might be way off so please jump in if I’m missing something…

maniqui wrote:

<!— About “have_match” variable: I suppose that if there aren’t any articles on category1, this will set value=”“ —>

Correct. Providing article_custom returns nothing, your value will hold nothing.

But you don’t need the first <txp:variable name="match_category" value='<txp:category1 />' /> since you are embedding category1 directly in the article_custom tag.

I think this is all you need:

<txp:if_individual_article>
<h3>Related Articles</h3>

<txp:variable name="has_match" value='<txp:article_custom limit="1" category='<txp:category1 />' />' />

<txp:if_variable name="has_match" value="">
  <p>No related articles.</p>
<txp:else />
  <txp:article_custom limit="99" category='<txp:category1 />' wraptag="ul" break="li">
    <txp:permlink><txp:title /></txp:permlink>
  </txp:article_custom>
</txp:if_variable>

</txp:if_individual_article>

I don’t think you need to load the has_match variable with the result of all 99 articles; that just makes a very loooong variable value and the goal (I think) is just to see if at least 1 article is returned. So you might as well just test to see if 1 article is returned by article_custom for that category and then perform the article_custom for real if that passes the test ;-)

Does that make sense or have I misunderstood?

P.S. on the examples front, I’m putting something together for (hopefully) next week. Watch the forum.

Last edited by Bloke (2008-07-03 23:51:34)


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

#63 2008-07-04 00:04:55

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Central storage for site-wide constants: Helpful?

Thanks for the correections, Bloke. It seems all them apply correctly and perfectly to the code I posted…

I think… time has arrived for a new attribute for txp:article and txp:article_custom.
What do you think about asking devs to add a count attribute which just returns the number (quantity) of matched articles. Like a pgonly, but it just returns a quantity.
Then you can set any variable value to a specifc number and do some conditionals to test the value.
Of course, in the future, another improvement could be adding support for less, more, equal to txp:if_variable.

Of course, the crazy guy (the one who posted above me) have some plug-ins that already can do that, as I understand.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#64 2008-07-04 00:36:54

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: Central storage for site-wide constants: Helpful?

maniqui wrote:

Of course, in the future, another improvement could be adding support for less, more, equal to txp:if_variable.

Yup, I think this can be very useful :)

Of course, the crazy guy (the one who posted above me) have some plug-ins that already can do that, as I understand.

Brings me to this question: Can we inject a variable into the value fields of an smd_if comparison by means of the new tag parser, Stef?

Bloke wrote:

P.S. on the examples front, I’m putting something together for (hopefully) next week.

Nice! Thanks for your efforts! :)
BTW, if txp:variable and smd_var can interact, would you give also examples on this, please?

Last edited by uli (2008-07-04 00:38:01)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#65 2008-07-04 00:49:37

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

Re: Central storage for site-wide constants: Helpful?

maniqui wrote:

add a count attribute which just returns the number (quantity) of matched articles. Like a pgonly, but it just returns a quantity.

Perhaps, but it may be a little “expensive” in terms of processing just to get the count because it’s got to load all that data in and populate the articles etc. Of course, I’ve no idea how pgonly works so it might be trivial insofar as it bypasses all the difficult stuff and terminates once it’s done the query.

There’s also always jmd_count I suppose.

Then you can set any variable value to a specifc number and do some conditionals to test the value… support for less, more, equal to txp:if_variable… some plug-ins that already can do that, as I understand.

:-D

If you want to do anything other than a straight equality comparison, smd_if is still the man. Internally it’s a very ugly man, but it is the man.

txp:var support is not built into smd_if (yet) for the field attribute; it needs three more lines of code adding. But until I get round to it Uli, there is nothing stopping you using it — or another tag — directly either as a field or a value. So, if you really want to bake your noodle:

<txp:if_search>

    <!-- This holds the tag we want to look in -->
<txp:variable name="test_me" value='<txp:search_result_term />' />

    <!-- List of rude words -->
<txp:variable name="obscenities" value="blob, fudge, barnacle, throcking, rumbelows" />

    <!-- Assume search is clean to start with -->
<txp:variable name="search_ok" value="1" />

    <!-- loop over each rude word -->
<txp:smd_each type="txpvar" include="obscenities" subset="2">

      <!-- See if the search_term contains the current word -->
  <txp:smd_if field='<txp:variable name="test_me" />' operator="contains" value="{var_value}">

        <!-- If so... NAUGHTY PERSON, thus change the search_ok flag to 0 -->
    <txp:variable name="search_ok" value="0" />
  </txp:smd_if>
</txp:smd_each>

  <!-- Now test the variable to see if the search term was clean and return the results if so -->
<txp:if_variable name="search_ok" value="0">
  <p>Stop being rude!</p>
<txp:else />
  <txp:article listform="search_results" />
</txp:if_variable>

</txp:if_search>   

How’s that ? :-)


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

#66 2008-07-07 18:39:27

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Central storage for site-wide constants: Helpful?

making the author’s comments different from the reader’s comments

This could be another case for our new txp:variable / txp:if_variable tag and the new tags-in-tags parser:
Mmm… in fact, it could be a task just for the new tags-in-tags parser, but I will post it here just because… I’m already writing here and… because there are too many clever minds posting in this thread…

In your “comments” TXP form, this may work

<txp:if_article_author name='<txp:author />'>
<div class="comment-by-author">
...
</div>
</txp:if_article_author>

edit: this example doesn’t makes any sense at all. Go on.

Last edited by maniqui (2008-07-08 01:42:59)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#67 2008-07-07 19:10:01

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

Re: Central storage for site-wide constants: Helpful?

maniqui wrote:

making the author’s comments different from the reader’s comments

Too Funny. Even Erie. I’ve literally been working on the same thing this afternoon.

Mike

Offline

#68 2008-07-07 19:15:22

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

Re: Central storage for site-wide constants: Helpful?

Me too *twilight zone music*. It was for the collection of examples I mentioned above. I’ll probably take my example out and point to Maniqui’s instead. Why reinvent the wheel, eh?!

Last edited by Bloke (2008-07-07 21:08:29)


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

#69 2008-07-07 19:18:49

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

Re: Central storage for site-wide constants: Helpful?

maniqui wrote:

In your “comments” TXP form, this may work
bc.. <txp:if_article_author name=’<txp:author />’>
<div class=“comment-by-author”>

</div>
</txp:if_article_author>

Its obvious how the conditional allows you to selectively choose the class. But don’t you need to then pass the class to <txp:comments />?

Maybe something like

<txp:if_article_author name=’<txp:author />’>
<txp:variable name=“comment_class” value=“comment-by-author” />
<txp:else>
<txp:variable name=“comment_class” value=“regular_comment” />
</txp:if_article_author>

<txp:comments class=’<txp:variable name=“comment_class” />’ />

Last edited by maverick (2008-07-07 19:19:49)

Offline

#70 2008-07-07 19:23:00

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Central storage for site-wide constants: Helpful?

Yes, my approach was a quick and dirty one, to be improved.

Yours is nicer, maverick.
And you have used both the tags-in-tags and variable tags, so it fits nice in this thread.

Last edited by maniqui (2008-07-07 19:24:02)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#71 2008-07-07 19:27:11

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

Re: Central storage for site-wide constants: Helpful?

maniqui

Your version looks much more simple. I was just drawing a mental block on how it set the class for the comment tag. But I’ll play with it and I’m sure the light will go on! :-)

Mike

Last edited by maverick (2008-07-07 19:29:15)

Offline

#72 2008-07-07 20:27:59

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

Re: Central storage for site-wide constants: Helpful?

Hmm. My way may have looked nicer and relevant to the forum, but doesn’t do the job. Besides several changes in order for make it work, right now it indiscriminately applies the author class to all comments when the author is logged in, or conversely, the non-author class to every comment. Somehow I need to compare the comment author to the article author and then pass the class when that condition is met.

<big smile>
We don’t have a <txp:if_comment_author=article_author> conditional tag yet, do we ;-P

Or maybe a <txp:if_variable name=“comment_author” /> = <txp:variable name=“article_author” />

</big smile>.

edit

maniqui – I see you already noted the need for <=> operations. Sorry I missed your post. Didn’t mean to repeat needlessly.

Last edited by maverick (2008-07-07 20:33:12)

Offline

Board footer

Powered by FluxBB