Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2008-07-02 10:49:30

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

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

Very sweet little examples for txp_var, Robert and Stef. I’m beginning to see the light ;)


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

Offline

#38 2008-07-02 11:50:06

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

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

Would this give just todays articles, then?

<txp:variable name="today" value='<txp:php>echo date("Y-m-d");</txp:php>' />
<txp:if_variable name="today" value="<txp:posted format="%Y-%m-%d" />"/>
<txp:output_form form="my_article" />
<txp:else />
No events today!
</txp:if_variable>

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

Offline

#39 2008-07-02 11:57:39

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

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

At first glance, this is almost working. if_variable receives a Textpattern tag as the attribute’s value, so you would need to enforce parsing with single quotes around <txp:posted format="%Y-%m-%d" />.

<txp:variable name="today" value='<txp:php>echo date("Y-m-d");</txp:php>' />
<txp:if_variable name="today" value='<txp:posted format="%Y-%m-%d" />' />
<txp:output_form form="my_article" />
<txp:else />
No events today!
</txp:if_variable>

Offline

#40 2008-07-02 14:42:59

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

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

uli wrote:

… I’m beginning to see the light ;)

Well now I can see the light fully. It’s strange but as soon as I read wet’s odd/even example my brain switched to “php mode” and all became clear in a second. Very strange, previously I had an hard time understanding… probably it’s me being completely brain-dead.
Anyway – as ever – thanks, very appreciated

Offline

#41 2008-07-02 16:26:50

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

OK, here’s an idea…

For an upcoming project, I’ve decided to adapt this geographic selector to instead show a map of a facility and the various events that are going on at present, and immediately following.

The current region selector is based on articles that have a regional multi-select custom field (thanks to gerhard lazu). Then articles for a region are listed inside a dd and shown with a hover over the associated “visual” dt. Right now I’m using multiple article_custom calls that make each region’s dd.

The new idea would have to use custom fields for day, time and room. Then list events in a room’s dd based on a comparison between “now” == “day+time”.

It all seems theoretically possible, but the specifics are eluding me, and my cranium is minuscule in comparison with those of you gents…

Last edited by mrdale (2008-07-02 16:32:11)

Offline

#42 2008-07-02 18:03:50

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

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

mrdale wrote:

Then list events in a room’s dd based on a comparison between “now” == “day+time”.

Should be doable for smd_query, I think.


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

Offline

#43 2008-07-02 20:33:27

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

Oh yeah, that makes sense. Just need to put together a query…

Offline

#44 2008-07-02 20:43:07

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

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

I think I’m getting it (but not quite sure yet…). Would this work (in an – individual – article form)?

<txp:if_individual_article>

<h3>Related Articles</h3>

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

<txp:article_custom limit="5">
	<txp:if_article_category name='<txp:variable name="match" />'>
		<txp:if_first_article><ul></txp:if_first_article>
		<li><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ul></txp:if_last_article>
	<txp:else />
		<p>No related articles.</p>
	</txp:if_article_category>
</txp:article_custom>

</txp:if_individual_article>

Offline

#45 2008-07-02 20:46:29

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

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

mrdale

Is this still related to your foreach thing? I couldn’t quite get my head round your problem. If I get a chance I’ll take another gander.


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

#46 2008-07-02 22:07:00

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

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

Els wrote:

I think I’m getting it (but not quite sure yet…). Would this work (in an – individual – article form)?

<txp:if_individual_article>

<h3>Related Articles</h3>

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

<txp:article_custom limit="5">
	<txp:if_article_category name='<txp:variable name="match" />'>
		<txp:if_first_article><ul></txp:if_first_article>
		<li><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ul></txp:if_last_article>
	<txp:else />
		<p>No related articles.</p>
	</txp:if_article_category>
</txp:article_custom>

</txp:if_individual_article>

Ah… my queen… I think we are getting there together… beautiful example… but your king thinks it may not work not be optimal…

<txp:article_custom limit="5">
	<txp:if_article_category name='<txp:variable name="match" />'>
                [...]
	<txp:else />
		<p>No related articles.</p>
	</txp:if_article_category>
</txp:article_custom>

</txp:if_individual_article>

At a first look, I though the <p>No related articles.</p> won’t eever get to the output, because I think there is no reason for a <txp:article_custom></txp:article_custom> to output anything if the query returns no article at all.
But then I re-read your code and if I’m right, this <txp:article_custom limit="5"> will fetch last five (sort defaults to Post desc) articles from all sections (defaults to all sections), from category(es) (defaults to all categories), etc.
And then, <txp:if_article_category name='<txp:variable name="match" />'> will “filter” your results. So, then, if there aren’t any article form the related category inside those five (limit="5") articles, you won’t get nothing, even if they are related articles somewhere in your site.

Being that limit="5" isn’t that much, it may not hurt performance.

So, I would rewrite it like this:

<txp:if_individual_article>

<h3>Related Articles</h3>

<txp:chh_if_data>
    <txp:article_custom section='<txp:section />' category='<txp:category1 />' limit="5" wraptag="ul" break="li">
        <txp:permlink><txp:title /></txp:permlink>
    </txp:article_custom>
<txp:else />
     <p>No related articles.</p>
</txp:chh_if_data>

</txp:if_individual_article>

edit: remove some typos and the txp:variable unneeded.

(Probably there is a way without using chh_if_data too)

Last edited by maniqui (2008-07-02 22:29:29)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#47 2008-07-02 22:15:49

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

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

*scratches head*

You lost me there maniqui, sorry :-) Where does the <txp:variable /> factor into your code? Is it needed?

Perhaps it’s too late; my brain’s about to implode anyway from a day of beating my head against this new plugin of mine.

Last edited by Bloke (2008-07-02 22:16:46)


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

#48 2008-07-02 22:28:43

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

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

Hehehe… I forgot to remove it…
I think it’s not needed, so my example is not for the “Central storage for site-wide constants” thread but for the “Tags in tags” thread.

I have edited the example above to remove txp:variable and a typo.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB