Generating A-Z lists of links to child pages (of the current page) - Antimatter theme - worked as expected, AT FIRST. Now, suddenly, the p.title property works fine but p.url is garbled in a way that GRAV is unable to follow its own-generated route.
As in:
In a page (typically a page with many children), looping through the child page list in a specified order.
Interestingly I can assign (write) p.url to any other property of the <a> tag, for example a data-url property, and the twig reference to p.url is displayed correctly.
This is my first brush with GRAV. Possibly this stopped working as usual after switching themes briefly from antimatter to quark and back to antimatter again.
Locally (WAMP server) two installed plugins were fully updated during this time:
the forms plugin
the flex-objects plugin
The other modified SINGLE FILE in the shortcode-core plugin is:
Lastly, locally during this time I installed
Trilby's page-toc plugin and
a plugin named snipcart
Given that my {{ p.url }} links are still intact on my remote/testing site, is it possible that one or the other of these plugin updates could produce this bug?
You are 100% correct. When I ask twig to loop over some page collection and generate <a> links to each child/descendent/post in HTML, twig will commit the {{ p.url }} value to ANY OTHER ATTRIBUTE of the <a> element, such as ...data-url="{{ p.url }}..." HOWEVER NOT THE HREF ATTRIBUTE:
Using a filter like |raw or |urlencode is ignored. I tried twig string interpolation to solve the problem but that too produces the output in HTML shown above.
Is there perhaps some other twig filter I could/should be using to commit a {{ ... }} value to the <a href="..."> attribute?
Again, I came up with the following site-wide workaround for this using js/jQuery, saved to a file I named: repair_urls.js
JS
$(document).ready(function(){$("a[data-url]").each(function(){/* provided all twig loops over any page collection
assign the p.url value to BOTH the href attribute of <a>
as well as an attribute deliberately named: data-url
*/$(this).click(function(){letgoChild=$(this).data("url");window.location.assign(goChild);returnfalse;})});});
To re-enable bastardized links generated by twig that SHOULD point to the URL or route of each page in a collection (BUT DON'T) we simply overwrite/correct the href attribute using the intact value in data-url (once the page is fully loaded).
Here's how it looks to twig:
TWIG
<ul>{%forpinpages%}<li><dl><dt><adata-url='{{p.url}}'href="{{p.url}}">{{p.title}}</a></dt><dd>{{p.header.event.start|date('l F jS, Y', 'America/New_York')}}</dd><dd> From: {{p.header.event.start|date('g:ia', 'America/New_York')}}</dd><dd> To: {{p.header.event.end|date('g:ia', 'America/New_York')}}</dd><dd> Location:
{{p.header.event.location}}</dd></dl></li>{%endfor%}</ul>
@boatful, You haven't provided much context, so I've been trying to figure out what's happening. I can finally reproduce the issue when using the following:
It's clearly an issue introduced by plugin page_toc and the issue has been reported before in June 2022 but hasn't received much attention (yet).
You might consider a separation of concerns and generate the Toc and the url list outside Markdown in their own reusable partial templates. In my view, Markdown in default.md is content, and a list of pages and toc are meta data.
Perhaps using twig_first: true is the remedy. Twig WAS outputting <a href="%7B%7B%20page.url%20%7D%7D">...</a> on a page of mine that loops over a collection of pages using:
YAML
collection:items:taxonomy.type:event
Then, when I added to the frontmatter:
YAML
----------title:Eventstwig_first:true
the values ascribed to the href properties in the output reverted to usable/expected/root-relative links:
@boatful, In that case, your use-case (which is still unclear to me) is different from the one I described above, because in my case twig_first: true resulted in anchors wrapped in a code block as follows: