Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2016-11-28 17:01:25

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Valueless attributes - ELI5 and further reading?

Oleg, you dangle tantalising carrots … but often they’re just out of my (mental) reach :-) If you have the time, could you expand on your example with all the associated bits?


TXP Builders – finely-crafted code, design and txp

Offline

#14 2016-11-28 18:25:56

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Valueless attributes - ELI5 and further reading?

Hehe, I’ll loose all the aura if I explain, that’s holy easy. Suppose, you want to output this (which I won’t explain, ask Pete):

<txp:if_category>
	<txp:output_form form="category" />
<txp:else />
	<txp:if_author>
		<txp:output_form form="author" />
	<txp:else />
		<txp:if_search>
			<txp:output_form form="search" />
		<txp:else />
			<txp:output_form form="home" />
		</txp:if_search>
	</txp:if_author>
</txp:if_category>   

where category form contains something like Category: <txp:category title="1" />, and so on. The only difference between the cases above is the form name. Let’s try to detect it. As said before, <txp:if_... /> will output 1 if its condition is met, or nothing otherwise. So

category<txp:if_category />/author<txp:if_author />/search<txp:if_search />/home1

will output

category/author1/search/home1

in not category, author, not search branch, where we want to call author form. It remains to extract author from this string, which is easy in PHP:

<txp:php>strtok('category/author1/search/default1', '1');</txp:php>

returns the portion of this string before the first 1, i.e. category/author. Next,

<txp:php>basename('category/author');</txp:php>

returns the last not-empty chunk from category/author split by /, i.e. author, as needed.

So, the initial block can be replaced with

<txp:variable name="case" value='<txp:php>
	$string = parse("category<txp:if_category />/author<txp:if_author />/search<txp:if_search />/home1");
	$branch = strtok($string, "1");
	echo basename($branch);
</txp:php>' />

<txp:output_form form='<txp:variable name="case" />' />

which I just wrapped in etc_query:

<txp:etc_query name="case" query="$strtok($|1).basename"
	data='category<txp:if_category />/author<txp:if_author />/search<txp:if_search />/home1' />

<txp:output_form form='<txp:variable name="case" />' />

Offline

#15 2016-11-28 18:56:54

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Valueless attributes - ELI5 and further reading?

etc wrote #303056:

Hehe, I’ll loose all the aura if I explain, that’s holy easy. Suppose, you want to output this (which I won’t explain, ask Pete):

<txp:if_category>
	<txp:output_form form="category" />
<txp:else />
	<txp:if_author>
		<txp:output_form form="author" />
	<txp:else />
		<txp:if_search>
			<txp:output_form form="search" />
		<txp:else />
			<txp:output_form form="home" />
		</txp:if_search>
	</txp:if_author>
</txp:if_category>   

I’ve posted this on the forums before.

<txp:variable name="task" value="frontpage" />

<txp:if_category><txp:variable name="task" value="category" /></txp:if_category>

<txp:if_search><txp:variable name="task" value="search" /></txp:if_search>

<txp:if_author><txp:variable name="task" value="author" /></txp:if_author>

<txp:output_form form="task-<txp:variable name="task" />" />

Personal Note: I have always found this annoying. I wish we could designate a specific page template for all three of these like we do with the error page. I like to keep the templates as simple as possible.

Offline

#16 2016-11-28 21:07:34

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Valueless attributes - ELI5 and further reading?

michaelkpate wrote #303057:

I’ve posted this on the forums before.

Haha, yes, it’s way smarter!

Offline

#17 2016-11-28 21:25:39

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,134
GitHub

Re: Valueless attributes - ELI5 and further reading?

etc wrote #303056:

Hehe, I’ll loose all the aura if I explain, that’s holy easy. Suppose, you want to output this (which I won’t explain, ask Pete):

etc, you’ll always be enigmatic in my book. Never fear.

Part of the reason for the extensive number of checks in the example code was to cover all pages states across all sections. It’s possible to have search/category/author pages in the root as well as subsections, and I’m finally getting around to boilerplate-ing my setup for future Textpattern theme work.

The most sensible thing I can do (I think) is have one tag soup recipe to determine the page state, and store the result it as a variable, rather then chewing through it over and over for titles, content, asides, footers and so forth.

Nothing to do with valueless attributes, after all.

When I’ve cleared a few millstone work projects and have a fresh set of eyes, I’ll take a look at your walkthrough above. Thank you for your advice and explanations.

Offline

#18 2016-11-28 22:07:59

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Valueless attributes - ELI5 and further reading?

etc wrote #303067:

Haha, yes, it’s way smarter!

Not really – just a different approach. :)

I have a bad habit of forgetting what some block of code is supposed to do when I don’t look at it for awhile so I try to keep things as simple for me as possible so I can figure it out later.

Offline

#19 2016-11-28 22:50:39

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

Re: Valueless attributes - ELI5 and further reading?

gaekwad wrote #303068:

The most sensible thing I can do (I think) is have one tag soup recipe to determine the page state, and store the result it as a variable, rather then chewing through it over and over for titles, content, asides, footers and so forth.

FWIW, this is the approach I took with TXP Mag. I had a colossal form called “context” or something which was called at the top of every page. Its job was to ascertain from the URL what the user was looking at: a bio page; an individual issue page; articles by author; the current issue landing page; an archived issue landing page from another year/quarter; and so forth.

It extracted the relevant items such as issue number/date/section/category/author from the (often gbp_permanent_links-style) URL and made <txp:variables> out of everything pertinent, which could be tested further down the page to display different sidebar contents, blocks, adverts, bio info, articles, etc.

If I had etc-fu, I’d have made it uber-terse to keep the amateurs out. But since I’m not that clever, I settled for doing it longhand, with copious <txp:hide> comment blocks so when I came back to it six months later I (or someone else) didn’t have to learn it all again to figure out why something wasn’t working.


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

#20 2016-11-29 10:22:33

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: Valueless attributes - ELI5 and further reading?

I’m sure it’s possible to do something with <txp:page_url /> tag.

With this tag, I wanted to create an “ouput_form” that returns a variable “context”.
Or a <txp:context /> tag with smd_macros plugin.
But I never took the time to experiment :(.

Offline

Board footer

Powered by FluxBB