Closed aloco closed 1 year ago
Sprig uses htmx and any s-
attributes map directly to their hx-
equivalents (that exist), so s-push-url
will work exactly the same as hx-push-url
. Does that answer your question?
Hi Ben,
thank you for the fast reply. This part is clear, however how can I read those segments on initial page load within twig? So when going directly to https://example.dev/news/1
and having no s-vals
used on button clicks, how can I use /1
from the url? Do I have to use craft.app.request.segments
and read them manually or is there any build in sprig magic for that?
Yes, you have all of Twig at your fingertips, so I’d suggest using this approach, for example.
{{ sprig('_my-component', { page: craft.app.request.segment(2) ?? 1 }) }}
Hi Ben, ok thank you! We will give it a shot
Hi,
we often get the requirement to deeplink paginated views. This is already possible, thanks to
s-push-url
however, when talking with SEO experts, we always hear "don´t use query parameters, use URL´s" or "paginated views need canonical URLs which includes the current page"So instead of having
https://example.dev/news?page=1
we would like to achieve something likehttps://example.dev/news/1
We are using SEOmatic most of the time, ideally the canonical URL is alsohttps://example.dev/news/1
and nothttps://example.dev/news
. While this can be achieved by overwriting the canonical URL manually, I don´t see a clean way to read the URL segments as variables in sprig/twigI recognized, that in htmx you can already do
hx-push-url="/1"
-> https://htmx.org/attributes/hx-push-url/ is this also possible with sprig?Thank you!