Skip to content

如何在模板中获取到当前页面url? #6824

Answered by guqing
WAGFS asked this question in Q&A
Discussion options

You must be logged in to vote
  1. 在Thymeleaf 模板中想要获取到当前页面url

${#ctx.getExchange().getRequest().getPathWithinApplication()}

  1. 有没有什么配置可以让模板变量中返回的url为绝对路径

目前没有提供这样的方法,只能通过 js 实现,可以使用 https://alpinejs.dev/ 这样的库来配合写模板可能是一个好的办法

  1. 文章页有没有模板变量可以返回纯文字的文章内容

没有,参考第 2 点,示例项目 https://github.com/halo-dev/theme-earth/blob/main/src/alpine-data/share.ts

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@WAGFS
Comment options

@holwell
Comment options

Answer selected by WAGFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants