Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-07-28 00:50:07

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

<txp:body /> parse an ID for his first element

Does anyone have any idea how I could assign an ID to the first element of <txp:body />? Without to set the ID in Textile.

Offline

#2 2011-07-28 02:35:50

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: <txp:body /> parse an ID for his first element

I guess you could do that with Javascript or, depending on what you are doing, try CSS with something like :first-child.

Offline

#3 2011-07-28 03:05:25

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: <txp:body /> parse an ID for his first element

Yes, in certain situations that could help. But I want something different.

My individual article form is:

<h1><txp:title /></h1>

<txp:if_excerpt>
	<txp:excerpt />
</txp:if_excerpt>

<txp:body />

Excerpt shows the first part of the article in the article list and in the individual article, and there body the rest. If someone clicks in the article list to “more”, he sees the full article, as usual.

With an ID at the point where the continuation of the individual article begins, one could directly jump to it. But, this point can be an <h2> or a paragraph … The only point of reference in the form is <txp:body />. I could put <txp:body /> inside a <div id="continuation">, but maybe someone knows a more elegant solution.

I hope I could explain my idea better now.

Offline

#4 2011-07-28 06:56:13

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

Re: <txp:body /> parse an ID for his first element

Why not do something as simple as:

<a id="continuation"></a><txp:body />

Offline

#5 2011-07-28 13:30:40

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: <txp:body /> parse an ID for his first element

wet schrieb:

Why not do something as simple as (…)

As I wrote earlier, this would be a solution:

<h1><txp:title /></h1>

<txp:if_excerpt>
	<txp:excerpt />
</txp:if_excerpt>

<div id="continuation">
	<txp:body />
</div>

It would just be nice if the additional DIV would not be necessary.

Offline

#6 2011-07-28 14:04:10

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

Re: <txp:body /> parse an ID for his first element

What’s your consideration about sparing that div? I can see no apparent problem there…


A hole turned upside down is a dome, when there’s also gravity.

Offline

#7 2011-07-28 15:36:11

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

Re: <txp:body /> parse an ID for his first element

GugUser wrote:

It would just be nice if the additional DIV would not be necessary.

Right. That’s why there is no additional DIV but only an anchor in the markup I proposed.

Offline

#8 2011-07-28 17:40:43

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: <txp:body /> parse an ID for his first element

jayrope wrote:

What’s your consideration about sparing that div? I can see no apparent problem there …

If the whole article is displayed, then it is semantically inconvenient to put a part of it into another block.

wet wrote:

Right. That’s why there is no additional DIV but only an anchor in the markup I proposed.

Yes, that’s is a better solution, if it can’t be avoided to put an additional element.

Here you can see what I mean and how I implemented it.

Offline

#9 2011-07-28 18:55:31

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

Re: <txp:body /> parse an ID for his first element

To me, wet’s approach seems cleaner/semantic-er than trying to add an ID on the first element on body, for each article.

It also helps to keep better separated content from behavior. You want that ID just to achieve some functionality/behavior. But, if tomorrow, you decide you don’t want that behavior (page jumping/scrolling to the first element of article’s body), you won’t need nor want that extra ID hanging on every first element of all your articles’ body (I’m assuming that it would be added to the database, as part of the article’s body field).

So, I’d go with wet’s suggestion (adding a dummy, empty, but semantic anchor) or with maruchan’s suggestion (doing it via Javascript).


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#10 2011-07-28 19:02:36

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

Re: <txp:body /> parse an ID for his first element

Thanx for the reasoning, the anchor version makes mostvsense to me as well, was just interested in hearing your reasons. Learn mode.


A hole turned upside down is a dome, when there’s also gravity.

Offline

#11 2011-07-29 01:52:16

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: <txp:body /> parse an ID for his first element

The anchor is not my desired solution, but I can live with it. There are more serious problems than this in our world …

Nevertheless, a few comments: I can not imagine a javascript based solution, because JS is a clientside parsed solution, and the Textpattern tag <txp:body /> is serverside parsed. And it isn’t defined how many paragraphs has each <txp:excerpt />, if <txp:body /> begins with h2 or paragraph etc. How should be selected the element?

maniqui wrote

But, if tomorrow, you decide you don’t want that behavior (page jumping/scrolling to the first element of article’s body), you won’t need nor want that extra ID hanging on every first element of all your articles’ body.

That was not my idea. Of course this with the ID should be solved centrally, for example in the form for the individual article. Any change could be made ​​there. If this were not so, the author could set an ID in Textile.

My imagination was more towards a solution with PHP. Find the first element in each <txp:body /> and assign him the predefined ID. But I do not know how this could be done.

Offline

#12 2011-07-29 03:02:27

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

Re: <txp:body /> parse an ID for his first element

Nevertheless, a few comments: I can not imagine a javascript based solution, because JS is a clientside parsed solution, and the Textpattern tag <txp:body /> is serverside parsed. And it isn’t defined how many paragraphs has each <txp:excerpt />, if <txp:body /> begins with h2 or paragraph etc. How should be selected the element?

Good point.

My imagination was more towards a solution with PHP. Find the first element in each <txp:body /> and assign him the predefined ID. But I do not know how this could be done.

A quick search on Google lead to this and this.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB