Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[solved] active class on current article.
I am trying to assign an active class on the link of the current article.
<txp:article_custom label="Other <txp:section />" labeltag="h4" section='<txp:section />' limit="30" break="li" wraptag="ul" class="submenu">
<txp:permlink<txp:if_article_id> class="active"</txp:if_article_id>><txp:title /></txp:permlink>
</txp:article_custom>
does not work and neither does
<txp:article_custom label="Other <txp:section />" labeltag="h4" section='<txp:section />' limit="30" break="li" wraptag="ul" class="submenu">
<a href="<txp:permlink />"<txp:if_article_id> class="active"</txp:if_article_id>><txp:title /></a>
</div>
and
<txp:article_custom label="Other <txp:section />" labeltag="h4" section='<txp:section />' limit="30" wraptag="ul" class="submenu">
<li<txp:if_article_id> class="active"</txp:if_article_id>><txp:permlink><txp:title /></txp:permlink></li>
</div>
any ideas?
Is it maybe because I am using the /section/title
url schema?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [solved] active class on current article.
I can see why the first one wouldn’t work — I should think the tag parser would choke on that.
The second (and, I presume) the third do work; I just tested #2. Of course, I closed the block with </txp:article_custom>
instead of </div>
.
:)
Code is topiary
Offline
Re: [solved] active class on current article.
oops. It was right in front of me all the time. Thanks Jeff. here are the correct codes should anyone want to use it
<txp:article_custom label="Other <txp:section />" labeltag="h4" section='<txp:section />' limit="30" break="li" wraptag="ul" class="submenu">
<a href="<txp:permlink />"<txp:if_article_id> class="active"</txp:if_article_id>><txp:title /></a>
</txp:article_custom>
and
<txp:article_custom label="Other <txp:section />" labeltag="h4" section='<txp:section />' limit="30" wraptag="ul" class="submenu">
<li<txp:if_article_id> class="active"</txp:if_article_id>><txp:permlink><txp:title /></txp:permlink></li>
</txp:article_custom>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [solved] active class on current article.
Why don’t you use a form for output the article list?
You’ve got to install rvm_if_this_article plugin and use a form in the article_custom tag.
<txp:article_custom label="Other <txp:section />" labeltag="h4" section='<txp:section />' limit="30" wraptag="ul" class="submenu" form="your-form">
This is the form
<txp:rvm_if_this_article> <li><txp:permlink class="active"><txp:title /></txp:permlink></li> <txp:else /> <li><txp:permlink><txp:title /></txp:permlink></li> </txp:rvm_if_this_article>
Offline
#5 2011-01-23 12:32:32
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [solved] active class on current article.
Yiannis, are you saying that this: label="Other <txp:section />"
works (with the double quotes)???
Last edited by els (2011-01-23 12:32:45)
Offline
Re: [solved] active class on current article.
Els wrote:
Yiannis, are you saying that this:
label="Other <txp:section />"
works (with the double quotes)???
Hadn’t noticed that, but I tested the code as written, and it does indeed work. It works with label
because the tag gets caught on the second parse()
pass. Wouldn’t work for something like the section
attribute, though, where the parsing needs to happen on the first pass.
Code is topiary
Offline
Re: [solved] active class on current article.
@Edoardo
I was trying to achieve this without plugins.
@ Els
Yep you can see it in action on all individual articles on neme-imca.org
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#8 2011-01-23 12:48:41
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [solved] active class on current article.
jsoo wrote:
It works with
label
because the tag gets caught on the secondparse()
pass. Wouldn’t work for something like thesection
attribute, though, where the parsing needs to happen on the first pass.
I don’t think I fully understand this ;) but I take your word for it. Learned something new today, thanks :)
Offline
Re: [solved] active class on current article.
Txp parses the template twice when rendering the page. In most cases everything gets parsed on the first run. In fact, I don’t know of any core Txp tags that rely on the second pass. (Look at the bottom of a tag trace to see if secondpass
caught anything. If you run Yiannis’s code, you’ll see the section
tag there.)
I’ve never found a satisfactory explanation of why the second pass is needed. It does allow tricks such as re-running a tag that expects information from the first parse pass — a couple of my plugins do this, for picking up pagination info (avoiding the need for something like article pgonly="1"
). I would say it is certainly best practice to use proper tag-in-tag syntax, i.e., single quotes.
Code is topiary
Offline
Re: [solved] active class on current article.
jsoo wrote:
I would say it is certainly best practice to use proper tag-in-tag syntax, i.e., single quotes.
Corrected as per the specs. i didn’t actually noticed that until Els pointed it out. I guess that single quotes might even speed up the page by a nano-second
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline