Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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
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
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
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
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).
Offline
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
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.
Offline